【发布时间】:2018-01-10 19:34:42
【问题描述】:
一些样本数据
我有三个列表
loc <- c("A","A","A","B","B","B")
sub.loc <- c(1,2,3,1,2,3)
set.seed(123)
df1 <- as.data.frame(cbind(loc,sub.loc, round(rnorm(6),digits =2)))
df2 <- as.data.frame(cbind(loc,sub.loc, round(rnorm(6),digits =2)))
df3 <- as.data.frame(cbind(loc,sub.loc, round(rnorm(6),digits =2)))
list.name <- list(df1,df2,df3)
我想生成一个具有第三列 V3 的均值和 sd 的文件。
Something like:
loc sub.loc V3 v4
A 1 mean(c(-0.56,0.46,0.4)) sd(c(-0.56,0.46,0.4))
A 2 mean(c(-0.23,-1.27,0.11)) sd(c(-0.23,-1.27,0.11))
A 3 mean(c(-0.56,-0.69, 1.56)) sd(c(-0.56,-0.69, 1.56))
B 1 mean(c(0.07,-0.45,1.79)) sd(c(0.07,-0.45,1.79))
B 2 mean(c(0.13,1.22,0.5)) sd(c(0.13,1.22,0.5))
B 3 mean(c(1.72,0.36,-1.97)) sd(c(1.72,0.36,-1.97))
我在 `V3`` 列中的实际数据有 NAs
我想用 lapply
lapply(list.name, function(x) mean(x, na.rm = T))
lapply(list.name, function(x) sd(x, na.rm = T))
但是他们两个都给了我 NAs
【问题讨论】: