[R] Adding same items together in data.frame

John Kane jrkrideau at yahoo.ca
Sat May 14 16:54:31 CEST 2011


And another approach:
=================================================================
library(reshape2)
mydata <- data.frame(aa = sample(Cs(a,b,c,d,e),10,replace=TRUE),
          bb = sample(1:10, 10, replace=TRUE))
          
(m1 <- melt(mydata))
=================================================================

--- On Fri, 5/13/11, wong, honkit (Stephen) <honkit at stanford.edu> wrote:

> From: wong, honkit (Stephen) <honkit at stanford.edu>
> Subject: [R]  Adding same items together in data.frame
> To: r-help at r-project.org
> Received: Friday, May 13, 2011, 7:06 PM
> Dear All,
> I am new to R. I have a 2 column data frame with more than
> ten thousand
> rows. Something like below. I want to add up all duplicated
> items, e.g. the
> three "aa" add up together to get a single value gene=a,
> value=74. How can I
> do that?? Thanks for help !
> gene value
> aa     20
> bb     10
> cc     9
> aa     30
> aa     24
> dd     100
> ee     55
> .... ...
> Millions thanks.
> Best Regards,
> hon
> 
> WONG, Hon-Kit (Stephen)
> Cleary Lab, Dept of Pathology
> Stanford University
> 




More information about the R-help mailing list