library(recipes)
example_date <- data.frame(
dates = seq(as.Date("2010/1/1"), as.Date("2016/1/1"), by = "quarter")
)
example_datetime <- data.frame(
datetimes = seq(ISOdate(1993,1,1), ISOdate(1993,1,2), by = "hour")
)
rec <- recipe(~ dates, data = example_date) %>%
step_difftime(dates, time = as.Date("2010/1/1"))
difftime_obj <- prep(rec)
bake(difftime_obj, new_data = NULL)
recipe(~ dates, data = example_date) %>%
step_difftime(dates, time = as.Date("2010/1/1"), unit = "weeks") %>%
prep() %>%
bake(new_data = NULL)
recipe(~ datetimes, data = example_datetime) %>%
step_difftime(datetimes, time = ISOdate(1993,1,1), unit = "secs") %>%
prep() %>%
bake(new_data = NULL)
Run the code above in your browser using DataLab