group

Means for each level of a factor

Average: 5 (1 vote)

A person on the R-Help list wanted to find the mean of each group, based on ID. Their data looked like:

data<-data.frame(ID=rep(letters[1:4], 5), size=runif(20))

The person was trying to write a for loop, as most people generally do when first encountering R (I sure did), but as is the case with most procedures in R, what can be done with a for loop in other languages, can be done looplessly in R.

Read more

Syndicate content