partition_ranges: Split ranges into multiple records

Description Usage Arguments Value Examples

View source: R/partition_ranges.R

Description

Split ranges into multiple records

Usage

1
2
3
4
5
6
7
8
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

1
2
3
4
5
6
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 March 31, 2020, 5:17 p.m.