在r中查找数据帧中的均值和中值 [英] Finding means and medians across data frames in r
问题描述
我有几个数据框, 我可以使用 a
b
c
d
,每个列名都相同。我想找到这些数据帧的平均值和中值。换句话说,构造与 a相同大小的新的
mean
和 median
数据框, b
等等。
for
循环,但我敢打赌,使用R内置函数可以更快地完成此操作。
library(abind)
apply (abind(a,b,c,d,along = 3),c(1,2),median)
?
(在相应的slice上使用 rowMeans
)仍然会比 apply
ing 意味着
...我想在 Biobase
(Bioconductor)包中有一个 rowMedians
如果你真的需要速度?)
I have several data frames, a
b
c
d
, each with the same column names. I want to find the mean and median of those data frames. In other words, construct new mean
and median
data frames that are the same size as a
, b
, etc.
I could use a couple of for
loops, but I bet there is a slick way of doing this using the R built-in functions that would be faster.
Following Josh Ulrich's answer, how about
library(abind)
apply(abind(a,b,c,d,along=3),c(1,2),median)
?
(Using rowMeans
on the appropriate slice will still be faster than apply
ing mean
... I think there is a rowMedians
in the Biobase
(Bioconductor) package if you really need speed?)
这篇关于在r中查找数据帧中的均值和中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!