Re: [R] how to sort the contents of a list-object?

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian D Ripley (ripley@stats.ox.ac.uk)
Date: Wed 12 May 2004 - 18:39:42 EST


Message-id: <Pine.WNT.4.58.0405120935140.1648@auk>

On Wed, 12 May 2004, Martin Kerick wrote:

> I have a list-object RGList named RG containing two vectors (RG$R and RG$G)
> and a data.frame(RG$genes) with 8 variables. Each of the variables of the
> data.frame have the same length as the two vectors. I think the data in the
> RGList is structured in such a way, that the first entry in the vector RG$R
> belongs to the first entry in the data.frame variable e.g. RG$genes$Row.
> Now my question:

> Is it possible to sort the RGList object by the values of one variable of my
> data.frame e.g. RG$genes$Row without loosing the ties between the different
> parts of the list ?

Yes. Did you also want to know how? If so, see later.

But why? It looks like R and G should be additional columns of the data
frame and if you had a better data organization you would *know* what
matched what and operations like this would be obvious.

ord <- sort.list(RG$genes$Row)
RG <- lapply(RG, function(x) if(is.data.frame) x[ord,] else x[ord])

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:09 EST