expand_times: Expand timestamp ranges.

expand_timesR Documentation

Expand timestamp ranges.

Description

Expand timestamp ranges.

Usage

expand_times(
  df,
  start_var,
  end_var,
  name = "Expanded",
  fmt = "%Y-%m-%d %H:%M:%OS",
  vars_to_keep = NULL,
  unit = "hour",
  tz = "UTC"
)

Arguments

df

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

start_var

Start time column

end_var

End time column

name

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

fmt

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

vars_to_keep

Which columns you would like to keep

unit

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

tz

Desired time zone - defaults to UTC

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 15:00:00", "2019-01-01 14:00:00", "2020-01-01 19:00:00"),
end = c("2018-01-01 18:30:00", "2019-01-01 17:30:00", "2020-01-02 02:00:00")
)

expand_times(df, start_var = "start", end_var = "end",
vars_to_keep = c("id", "gender"), unit = "hour")


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