expand_dates {neatRanges}R Documentation

Expand date ranges.

Description

Expand date ranges.

Usage

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


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")


[Package neatRanges version 0.1.4 Index]