【发布时间】:2013-01-11 21:19:05
【问题描述】:
我有一个 list 或 data.frames。每个data.frame 不是很大~150,000 行。但我的列表中有超过 1000 个 data.frames。
data.frame 看起来像:
comp <- read.table(text = " G T H S B
1 1 1 1 x1
1 1 1 2 x2
1 2 6 1 x3
1 2 6 2 x4
2 1 7 1 x1
2 2 8 2 x2
2 2 8 1 x1
2 3 9 2 x2",header=TRUE,stringsAsFactors=FALSE)
所以列表是:
complist <- list(comp,comp,comp)
我想知道每个data.frame、(comp)、每个S 中每个H 中每个T 中每个G 中的B 的长度。
所以对于我的小练习,我使用:
library(plyr)
listresults <- lapply(complist, function(x) {
res <- ddply(x, .(G,T,H,S),
function(z) data.frame(resultcol = length(z$B)) )
} )
但是在我更大的列表中,这非常长,有人可以帮我找到更快的方法吗? Aggregate 不是这里的选项,我一直未能使用 sapply(split)) 替代 ddply。建议即使不是实际代码也会对我有帮助。
【问题讨论】:
-
+1 为所有人。开始
data.table方法实际上已经完成了,虽然这需要一些学习。