try this: mat <- matrix(rnorm(1000), 100, 10) ind <- gl(4, 25)
rowsum(mat, ind) / rep(table(ind), each = ncol(mat)) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Manuel Montes" <[EMAIL PROTECTED]> To: <r-help@r-project.org> Sent: Tuesday, April 08, 2008 11:14 AM Subject: [R] tapply > Does anyone have something like tapply for matrices? I would like to > average the contents of columns > according to factors but tapply works only with one column at each > time. Is something available to do > everything in one step? > Many thanks. > Manuel Montes > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.