标记 ffdfdply 是 ffbase 的一部分,而不是 ff。为了展示 ffdfdply 的用法示例,让我们生成一个ffdf
50Mio 行。
require(ffbase)
data <- expand.ffgrid(Date = ff(seq.Date(Sys.Date(), Sys.Date()+10000, by = "day")), Item = ff(factor(paste("Item", 1:5000))))
data$sales <- ffrandom(n = nrow(data))
# split by date -> assuming that all sales of 1 date can fit into RAM
splitby <- as.character(data$Date, by = 250000)
grp_qty <- ffdfdply(x=data[c("sales","Date","Item")],
split=splitby,
FUN = function(data){
## This happens in RAM - containing **several** split elements so here we can use data.table which works fine for in RAM computing
require(data.table)
data <- as.data.table(data)
result <- data[, list(sales = sum(sales, na.rm=TRUE)), by = list(Date, Item)]
as.data.frame(result)
})
dim(grp_qty)
标记 grp_qty 是一个ffdf
驻留在磁盘上的。