[R] How to calculate the row wise means for grouped columns in matrix?

2010-01-15 Thread Joel Fürstenberg-Hägg
Hi all, I want to calculate the row wise mean of groups of columns in a matrix M. All columns belonging to the same group have the same column name. My idea is to create a new vector V containing these column names, but after first removing the duplicates. Then I would calculate the means

Re: [R] How to calculate the row wise means for grouped columns in matrix?

2010-01-15 Thread Benilton Carvalho
adapted from the help files of rowsum x - matrix(runif(100), ncol=5) group - sample(1:8, 20, TRUE) xsum - rowsum(x, group) sweep(xsum, 1, table(group), /) or aggregate(x, list(group), mean)[-1] b 2010/1/15 Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com: Hi all, I want to