expand_dates: Expand date ranges.

Description Usage Arguments Value Examples

View source: R/expand_variants.R

Description

Expand date ranges.

Usage

1
2
3
4
5
6
7
8
9
expand_dates(
  df,
  start_var,
  end_var,
  name = "Expanded",
  fmt = "%Y-%m-%d",
  vars_to_keep = NULL,
  unit = "day"
)

Arguments

df

Data frame (can also be a data.table or a tibble)

start_var

Start Date column

end_var

End Date column

name

The name of newly created column. Defaults to 'Expanded'

fmt

The format of date columns, defaults to Y-M-D

vars_to_keep

Which columns you would like to keep

unit

By which unit of time you want to expand; the default is day

Value

Returns a full data frame with expanded sequences in a column, e.g. by day or month.

Examples

1
2
3
4
5
6
7
8
9
df <- data.frame(
id = c("1111", "2222", "3333"),
gender = c("M", "F", "F"),
start = c("2018-01-01", "2019-01-01", "2020-01-01"),
end = c("2018-01-05", "2019-01-07", "2020-01-08")
)

expand_dates(df, start_var = "start", end_var = "end",
vars_to_keep = c("id", "gender"), unit = "day")

neatRanges documentation built on March 31, 2020, 5:17 p.m.