Calculating mean values corresponding to duplicate row names
1
0
Entering edit mode
Hari Easwaran ▴ 240
@hari-easwaran-3510
Last seen 9.5 years ago
United States
Hi all, I have a table (t) of the following format (first row is the header): A x1 x2 c 1 NA c 2 1002 c 3 NA a 4 1004 b 5 NA c 6 1006 c 7 1007 c 8 1008 b 9 1009 a 10 1010 a 11 1011 c 12 1012 c 13 1013 a 14 1014 c NA 1015 I want to find the mean of all the values corresponding to the row names "a", "b", "c" (which are duplicated). I tried the following which works: U <- unique(t$A) tt <- t(sapply(U, FUN=function(u) {mean(na.omit(t[t$A==u, ]))})) However, in reality the table t is real huge ( almost 44K rows and 100 columns). The above approach takes too long. Is there another alternative that anyone can think of. Thanks a lot for any help/suggestions. Sincerely, Hari [[alternative HTML version deleted]]
• 944 views
ADD COMMENT
0
Entering edit mode
@sean-davis-490
Last seen 3 months ago
United States
On Thu, Sep 24, 2009 at 2:49 PM, Hari Easwaran <hariharan.pe at="" gmail.com=""> wrote: > Hi all, > I have a table (t) of the following format (first row is the header): > A ? ? ? x1 ? ? ? ?x2 > c ? ? ? 1 ? ? ? ? ?NA > c ? ? ? 2 ? ? ? ? ?1002 > c ? ? ? 3 ? ? ? ? ? NA > a ? ? ? 4 ? ? ? ? ?1004 > b ? ? ? 5 ? ? ? ? ? NA > c ? ? ? ?6 ? ? ? ? ?1006 > c ? ? ? ?7 ? ? ? ? ?1007 > c ? ? ? ?8 ? ? ? ? ?1008 > b ? ? ? ?9 ? ? ? ? ?1009 > a ? ? ? 10 ? ? ? ? 1010 > a ? ? ? 11 ? ? ? ? 1011 > c ? ? ? 12 ? ? ? ? 1012 > c ? ? ? 13 ? ? ? ? 1013 > a ? ? ? 14 ? ? ? ? 1014 > c ? ? ? ?NA ? ? ? ?1015 > > > I want to find the mean of all the values corresponding to the row names > "a", "b", "c" (which are duplicated). > I tried the following which works: > U <- unique(t$A) > tt <- t(sapply(U, FUN=function(u) {mean(na.omit(t[t$A==u, ]))})) Take a look at the aggregate() function. Sean > However, in reality the table t is real huge ( almost 44K rows and 100 > columns). The above approach takes too long. Is there another alternative > that anyone can think of. > > Thanks a lot for any help/suggestions. > > Sincerely, > Hari > > ? ? ? ?[[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor >
ADD COMMENT

Login before adding your answer.

Traffic: 669 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6