简体   繁体   中英

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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