У меня есть датафрейм с другим идентификатором и именами. Вот небольшой пример
library(dplyr)
dframefull <- data.frame(id = c(1,1,1,1,1,1), name = c("Google", "Google", "Google", "Google", "Google", "Google"), date = c("26/8/2014 19:30:57", "27/8/2014 10:12:01", "27/8/2014 14:10:29", "27/8/2014 14:10:32", "27/8/2014 14:10:33", "3/9/2014 14:10:32"), mytext = c("text", "another", "text", "here", "other text", "text more"))
dframefull <- mutate(dframefull, date = as.Date(date))
У меня есть второй кадр данных, в котором указаны c даты. Например,
dframekeep <- data.frame(id = c(1), name = c("Google"), date = c("27/8/2014 14:10:32"))
dframekeep <- mutate(dframekeep, date = as.Date(date))
На основании указанных c дат я хотел бы хранить в течение 10 дней до даты второго кадра данных данные в одной строке и после точной второй (: 32 в примере ) другие данные за 10 дней после.
Вот пример ожидаемого выхода.
data.frame(id = c(1,1), label = c("before", "after"), name = c("Google", "Google"), mytext = c("text another text here", "other text text more"))
id label name mytext
1 1 before Google text another text here
2 1 after Google other text text more
Как это сделать. Это решение для дней