I have a data set that I would like to separate by 10-day intervals. For example, I would like to get all of the dates 26-12-2010 to 04-01-2011 for ID 1 together than the next 10-days for ID 1 together. I would like to do this for each ID, and compile the 10-day intervals into a list.
library(lubridate)
date <- rep_len(seq(dmy("26-12-2010"), dmy("20-12-2013"), by = "days"), 500)
ID <- rep(seq(1, 5), 100)
df <- data.frame(date = date,
x = runif(length(date), min = 60000, max = 80000),
y = runif(length(date), min = 800000, max = 900000),
ID)
df %>%
mutate(interval = map(1:50, ~rep(.x, 10)) %>% reduce(c)) %>%
group_split(interval) %>%
map(~arrange(.x, ID)) %>%
map(~ group_split(.x, ID)) %>%
head(2)
)
When using the last lines of code, it breaks the days and IDs but the observations that are suppose to be within 10-days are not being grouped together.