查找R数据帧的均值和标准差

时间:2016-03-12 13:08:43

标签: r dataframe

我有一个名为df的dataFrame,如:

temp1     temp2
  4         3
  3         6
  4         5

如何找到整个R dataFrame的均值和标准差?我试过这个

mean(as.matrix(df))

但是我收到了这个错误:

In mean.default(data) : argument is not numeric or logical: returning NA

1 个答案:

答案 0 :(得分:1)

在评论的两条建议中,as.matrix方法看起来很优秀:

microbenchmark(unlist = mean(unlist(iris[,1:4])), 
                 as.matrix = mean(as.matrix(iris[,1:4])))
## Unit: microseconds
##       expr    min      lq      mean  median      uq     max neval cld
##     unlist 236.82 237.961 245.47638 239.102 240.812 374.807   100   b
##  as.matrix  58.54  60.440  67.38185  61.961  68.613 273.694   100  a