Re: [R] Adding same items together in data.frame

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Sat, 14 May 2011 07:54:31 -0700 (PDT)


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))


> From: wong, honkit (Stephen) <honkit_at_stanford.edu>
> Subject: [R] Adding same items together in data.frame
> To: r-help@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
>



R-help_at_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. Received on Sat 14 May 2011 - 14:57:34 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 May 2011 - 16:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive