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.
Asked
Active
Viewed 352 times
0
-
3Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Dec 06 '15 at 16:09
1 Answers
0
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])

tagoma
- 3,896
- 4
- 38
- 57
-
Thanks for your answer but I think you misunderstood (my fault). I meant across columns rather than within. – R Beginner Dec 08 '15 at 16:00
-
I think this works: mean(cbind(df[,13], df[,15:17])) even though it is not elegant – tagoma Dec 08 '15 at 21:37