Hi, I have a 250,000 by 300 matrix. I am trying to calculate the median of those columns (by row) with column names that are identical. I would like this to be efficient since apply(x,1,median) where x is created by choosing only those columns with same column name and looping on this is taking a really long time. Is there an efficient way to do this? Thanks! [[alternative HTML version deleted]]
On Tue, May 22, 2012 at 01:34:45PM -0600, Preeti wrote:> Hi, > > I have a 250,000 by 300 matrix. I am trying to calculate the median of > those columns (by row) with column names that are identical. I would like > this to be efficient since apply(x,1,median) where x is created by choosing > only those columns with same column name and looping on this is taking a > really long time. Is there an efficient way to do this?Hi. Can you send a simple example of what you want to compute? The 300 medians of the 300 columns, each of length 250'000, may be computed using apply(x,2,median) and this does not take much time. What do you mean by "choosing only those columns with same column name"? Petr Savicky.
See rowMedians() of the matrixStats package for replacing apply(x, MARGIN=1, FUN=median). /Henrik On Tue, May 22, 2012 at 12:34 PM, Preeti <preeti at sci.utah.edu> wrote:> Hi, > > I have a 250,000 by 300 matrix. I am trying to calculate the median of > those columns (by row) with column names that are identical. I would like > this to be efficient since apply(x,1,median) where x is created by choosing > only those columns with same column name and looping on this is taking a > really long time. Is there an efficient way to do this? > > Thanks! > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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.