partition_ranges: Split ranges into multiple records

View source: R/partition_ranges.R

partition_rangesR Documentation

Split ranges into multiple records

Description

Split ranges into multiple records

Usage

partition_ranges(
  df,
  start_var,
  end_var,
  fmt = "%Y-%m-%d",
  vars_to_keep = NULL,
  partition_by = "year"
)

Arguments

df

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

start_var

Start variable

end_var

End variable

fmt

Format of the date; defaults to Y-m-d

vars_to_keep

Any column you'd like to retain (optional)

partition_by

How should the range be partitioned ('year' or 'month'); defaults to 'year'

Value

Returns a data frame with start, end and optional grouping columns

Examples


df <- data.frame(group = c("a", "a", "b", "b", "c"),
start = c("2017-05-01", "2019-04-03", "2011-03-03", "2014-05-07", "2017-02-01"),
end = c("2018-09-01", "2020-04-03", "2012-05-03", "2016-04-02", "2017-04-05")
)

partition_ranges(df, "start", "end", partition_by = "month")

neatRanges documentation built on Oct. 18, 2022, 9:08 a.m.