Reply to sender Reply to all Reply to folder Forward Move/Copy Delete Read previous item Read next item Get help information on the current window From: McMurtry, Benjamin G. To: 'r-help-request at stat.math.ethz.ch' Cc: Subject: Table Help Sent: 5/24/2005 4:33 PM Importance: Normal I have a very large table that I want to add some of the certain rows. The table is as follows: Username1 2 Username1 4 Username2 6 Username2 10 Username3 12 Username3 10 Username3 16 Etc .... The data is sorted by Column 1 (Ie the username) then by columm 2 (The numbers). I want to combine the rows so it would be as follows: Username1 6 Username2 16 Username3 38 Is there easy way using a feature like bind to sum all of collumn two where column 1 is the same? Thanks! Ben
I have a very large table that I want to add some of the certain rows. The table is as follows: Username1 2 Username1 4 Username2 6 Username2 10 Username3 12 Username3 10 Username3 16 Etc .... The data is sorted by Column 1 (Ie the username) then by columm 2 (The numbers). I do not know how many of each username I will have. I want to combine the rows so it would be as follows: Username1 6 Username2 16 Username3 38 Is there easy way using a feature like bind to sum all of collumn two where column 1 is the same? Thanks! Ben
see ?aggregate.... Sean On May 24, 2005, at 4:39 PM, McMurtry, Benjamin G. wrote:> > > Is there easy way using a feature like bind to sum all of collumn two > where > column 1 is the same?
I'm slightly confused with aggregate, will I need to loop it until it stops returning sub lists? Or would I somehow need to convert my username column into a unique list and then do FUN=sum?? Please excuse me, I was just introduced to R yesterday to calculate statistics of over 250 gigs of text we have lol. Thanks for the reply! Ben -----Original Message----- From: Sean Davis To: McMurtry, Benjamin G. Cc: 'r-help at stat.math.ethz.ch' Sent: 5/24/2005 4:56 PM Subject: Re: [R] Table Help see ?aggregate.... Sean On May 24, 2005, at 4:39 PM, McMurtry, Benjamin G. wrote:> > > Is there easy way using a feature like bind to sum all of collumn two> where > column 1 is the same?
On May 25, 2005, at 9:35 AM, McMurtry, Benjamin G. wrote:> I'm slightly confused with aggregate, will I need to loop it until it > stops > returning sub lists? Or would I somehow need to convert my username > column > into a unique list and then do FUN=sum??Ben, Generally, it is OK (and encouraged) to post back to the list, just so we all learn from each others' posts. Here is an example: > a <- data.frame(group=rep(letters[1:3],10),values=rnorm(30)) > a group values 1 a -0.146140983 2 b 0.190071267 3 c 0.207708591 4 a -1.126531350 5 b -0.013761243 6 c -0.212028409 7 a 1.012215244 8 b -0.487072132 9 c 0.667999520 10 a 0.276094321 11 b 0.835611948 12 c -1.049264490 13 a 0.399050191 14 b -1.177174650 15 c -1.471944114 16 a -0.410480517 17 b 0.006008521 18 c 1.608219688 19 a -0.120729414 20 b 1.074361542 21 c 1.782826882 22 a 1.336191577 23 b 0.721519413 24 c -0.594837423 25 a 1.120628507 26 b -2.011601905 27 c -0.076464599 28 a -1.512376840 29 b 1.182703732 30 c -1.620904211 > aggregate(a[,2],by=list(a[,1]),sum) Group.1 x 1 a 0.8279207 2 b 0.3206665 3 c -0.7586886 > Hope that helps. Sean