在r中查找数据帧中的均值和中值 [英] Finding means and medians across data frames in r

查看:106
本文介绍了在r中查找数据帧中的均值和中值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个数据框, a b c d ,每个列名都相同。我想找到这些数据帧的平均值和中值。换句话说,构造与 a相同大小的新的 mean median 数据框, b 等等。

我可以使用 for 循环,但我敢打赌,使用R内置函数可以更快地完成此操作。

解决方案

继Josh Ulrich的回答,如何

  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 applying mean ... I think there is a rowMedians in the Biobase (Bioconductor) package if you really need speed?)

这篇关于在r中查找数据帧中的均值和中值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆