我希望聚合列表中列中具有相同字符的所有数据帧行。为此我用了
You said, "It's around 15 MB".
工作正常。但是,我在列表中也得到了空dfs(我需要它,所以我不能删除它们)并且我收到错误:
lapply(lst, function(x) aggregate(Value ~ Area, x, sum))
有没有办法克服这个错误?谢谢。下面是一个小例子:
Error in aggregate.data.frame(mf[1L], mf[-1L], FUN = FUN, ...) :
no rows to aggregate
答案 0 :(得分:3)
lst <- list("111.2012"=data.frame("Area"=character(0), "Value"=numeric(0)),
"112.2012"=data.frame("Area"=c("a","b","b","a"), "Value"=c(1,5,3,2)))
lapply(lst, function(x) if (nrow(x)) aggregate(Value ~ Area, x, sum) else x)
输出
$`111.2012`
[1] Area Value
<0 rows> (or 0-length row.names)
$`112.2012`
Area Value
1 a 3
2 b 8