Hi Patrick,
does this help:
lst <- list(a=10, b=20, u=30, d=50)
lst[!is.na(match(names(lst), letters[1:10]))]
Best,
Dimitris
----
Dimitris Rizopoulos
Doctoral Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Patrick Joseph" <patrick_nospam@hotmail.com>
To: <s-news@wubios.wustl.edu>
Sent: Monday, August 23, 2004 4:19 PM
Subject: [S] How to drop null elements of a list?
>
> Hi,
>
> I have a list named lst which has an arbitrary number of named
elements. For
> example:
>
> >print(lst)
> $a:
> [1] 10
>
> $b:
> [1] 20
>
> I would like to extract the elements that match a vector of names
but I want
> the result contains only the matched elements. For example, if I do
the
> following command:
>
> >lst.match _ lst[c("a","c")]
>
> I would like the result:
> $a:
> [1] 10
>
> and not:
> $a:
> [1] 10
>
>
> $"":
> NULL
>
>
> Is there a simple way to do that (maybe something that uses drop)
other than
> doing a second command like:
>
> >lst.match[unlist(lapply(lst.match,function(x) !is.null(x)))]
>
> Thank you for any hint,
> Patrick
>
> _________________________________________________________________
> Take advantage of powerful junk e-mail filters built on patented
Microsoft®
> SmartScreen Technology.
>
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
> Start enjoying all the benefits of MSN® Premium right now and get
the
> first two months FREE*.
>
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu
with
> the BODY of the message: unsubscribe s-news
|