ffbase
provides the function ffdfdply
to split and aggregate data rows. This answer (https://stackoverflow.com/a/20954315/336311) explains how that can basically work. I still cannot figure out how to split by multiple columns.
My challange is that a split variable is required. This must be unique for each combination of the two variables, I'd like to split by. Still, in my 4-column data frame (about 50M rows), it would require a lot of memory, if creating a character vector by paste()
.
This is where I got stuck...
require("ff")
require("ffbase")
load.ffdf(dir="ffdf.shares.02")
# Aggregation by articleID/measure
levels(ffshares$measure) # "comments", "likes", "shares", "totals", "tw"
splitBy = paste(as.character(ffshares$articleID), ffshares$measure, sep="")
tmp = ffdfdply(fftest, split=splitBy, FUN=function(x) {
return(list(
"articleID" = x[1,"articleID"],
"measure" = x[1,"measure"],
# I need vectors for each entry
"sx" = unlist(x$value),
"st" = unlist(x$time)
))
}
)
Of course, I could use shorter levels for ffshares$measure
or simply use the numeric codes, but this still won't solve the underlying problem that splitBy
grows enormously large.
Sample Data
articleID measure time value
100 41 shares 2015-01-03 23:20:34 4
101 41 tw 2015-01-03 23:30:30 24
102 41 totals 2015-01-03 23:30:38 6
103 41 likes 2015-01-03 23:30:38 2
104 41 comments 2015-01-03 23:30:38 0
105 41 shares 2015-01-03 23:30:38 4
106 41 tw 2015-01-03 23:40:24 24
107 41 totals 2015-01-03 23:40:35 6
108 41 likes 2015-01-03 23:40:35 2
...
1000 42 shares 2015-01-04 20:10:50 0
1001 42 tw 2015-01-04 21:10:45 24
1002 42 totals 2015-01-04 21:10:35 0
1003 42 likes 2015-01-04 21:10:35 0
1004 42 comments 2015-01-04 21:10:35 0
1005 42 shares 2015-01-04 21:10:35 0
1006 42 tw 2015-01-04 22:10:45 24
1007 42 totals 2015-01-04 22:10:43 0
1008 42 likes 2015-01-04 22:10:43 0
...