I have this dataframe
dt <-
data.frame(
date = c(as.Date("2022-03-01"), as.Date("2022-03-02"), as.Date("2022-03-08"), as.Date("2022-03-08"), as.Date("2022-04-01"), as.Date("2022-04-10"))
)
My goal is to create new column in dplyr and assign 1/0 depending on date difftime in days. In case that difference is lower than 7, 0 schould be assigned and vice versa. Thus desired result is.
result <-
data.frame(
date = c(as.Date("2022-03-01"), as.Date("2022-03-02"), as.Date("2022-03-08"), as.Date("2022-03-08"), as.Date("2022-04-01"), as.Date("2022-04-10")),
cache = c(0, 1, 0, 1, 0, 0)
)