简体   繁体   English

如何计算R中不同列的均值

[英]How to calculate mean in different columns in R

I have a painfully simple question. 我有一个痛苦的简单问题。 Due to small sample sizes I want to group several species for analysis. 由于样本量较小,我想对几种物种进行分组以进行分析。 I am trying to make a new variable which has calculated the means of columns 13, 15, 16 and 17. 我正在尝试制作一个新变量,该变量计算了第13、15、16和17列的均值。

to compute the mean of a column, just call the colMeans function, eg to get the mean of the first column in the following dataframe example: 要计算列的平均值,只需调用colMeans函数,例如,在以下数据框示例中获取第一列的平均值:

df <- data.frame(rnorm(4),rnorm(4),rnorm(4))
meanFirstCol <- colMeans(df[1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM