I have this data:
library(dplyr)
dframefull <- data.frame(id = c(1,1,1,1,1,1,1,1), name = c("Google", "Google", "Google", "Google", "Google", "Google", "Google", "Google"), date = c("12/8/2014 19:30:57", "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", "14/9/2014 19:30:57"), mytext = c("out text", "text", "another", "text", "here", "other text", "text more", "out text 2"))
dframekeep <- data.frame(id = c(1), name = c("Google"), date = c("27/8/2014 14:10:32"))
and running this commands
b <- with(dframefull,
aggregate(list(mytext=mytext),
by=list(id=id,
label=factor(I(date > dframekeep$date), labels=c("before", "after")),
name=name),
FUN=paste))
And I receive this error:
Error in factor(I(date > dframekeep$date), labels = c("before", "after")) :
invalid 'labels'; length 2 should be 1 or 0
In addition: Warning message:
In Ops.factor(date, dframekeep$date) : ‘>’ not meaningful for factors
Any idea how can I fix it?
Expected result is to keep 10 days before and 10 days after the time stamp of the second dataframe taking into considaration the seconds
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