[R] Adding matrix rows that have the same name?

2010-03-23 Thread Sarah Berke
Does anyone know if there is an R function that will take a matrix like this jim 1 0 0 0 0 0 jim 0 1 0 0 0 0 jim 0 0 1 0 0 0 bob1 0 0 0 0 0 bob0 0 1 0 0 0 harry 0 0 1 0 0 0 harry 0 0 0 1 0 0 harry 0 0 0 0 1 0 harry 0 0 0 0 0 1

Re: [R] Adding matrix rows that have the same name?

2010-03-23 Thread Henrique Dallazuanna
Try this: aggregate(as.data.frame(dum.mat.temp), list(row.names(dum.mat.temp)), sum) On Tue, Mar 23, 2010 at 6:15 PM, Sarah Berke skbe...@gmail.com wrote: Does anyone know if there is an R function that will take a matrix like this jim     1  0  0  0  0  0 jim     0  1  0  0  0  0 jim     0

Re: [R] Adding matrix rows that have the same name?

2010-03-23 Thread Dennis Murphy
Hi: The plyr solution is as follows, where your 'matrix' is a data frame m whose first column is a factor: m V1 V2 V3 V4 V5 V6 V7 1 jim 1 0 0 0 0 0 2 jim 0 1 0 0 0 0 3 jim 0 0 1 0 0 0 4 bob 1 0 0 0 0 0 5 bob 0 0 1 0 0 0 6 harry 0 0 1 0 0 0 7