【发布时间】:2014-04-11 21:21:45
【问题描述】:
考虑以下示例:
require(MuMIn)
data(Cement)
d <- data.frame(Cement)
idx <- seq(11,13)
cor1 <- list()
for (i in 1:length(idx)){
d2 <- d[1:idx[i],]
cor1[[i]] <- cor.test(d2$X1,d2$X2, method = "pearson")
}
out <- lapply(cor1, function(x) c(x$estimate, x$conf.int, x$p.value))
在这里,我计算迭代循环中数据集的相关性。
我知道想要生成一个由“out”列表中的值组成的 data.frame。我尝试使用
df <- do.call(rbind.data.frame, out)
但结果似乎不对:
> df
c.0.129614123011664..0.195326511912326..0.228579470307565.
1 0.1296141
2 0.1953265
3 0.2285795
c..0.509907346173941...0.426370467476045...0.368861726657293.
1 -0.5099073
2 -0.4263705
3 -0.3688617
c.0.676861607564929..0.691690831088494..0.692365536706126.
1 0.6768616
2 0.6916908
3 0.6923655
c.0.704071702633775..0.542941653020805..0.452566184329491.
1 0.7040717
2 0.5429417
3 0.4525662
这不是我所追求的。
如何生成一个 data.frame,它的第一列表示计算了 cor.test 的列表,即在这种情况下为 1 到 3,第二列指的是 $estimate,然后是 $conf.int 和 %p .value 产生一个五列 data.frame。
【问题讨论】: