Skip to content
Prev 333576 / 398506 Next

averaging rows on a data.frame according to a factor

Sorry, there's a bug in my previous answer.

dat <- data.frame(c("a","a","a","b","b"), c(1,2,3,3,2), c(4,3,5,4,4))

aggregate(as.matrix(dat[,-1]) ~ dat[,1], FUN = mean)


Don't use as.data.frame(cbind(...)), everything becomes factors.

Rui Barradas

Em 22-11-2013 23:02, Rui Barradas escreveu: