Message-ID: <49AE9082.5080803@idi.ntnu.no>
Date: 2009-03-04T14:30:26Z
From: Wacek Kusnierczyk
Subject: Odp: Filtering R lists
In-Reply-To: <OF534601DE.324DED58-ONC125756F.0044DB93-C125756F.00468CD6@precheza.cz>
Petr PIKAL wrote:
> Hi
>
>
> r-help-bounces at r-project.org napsal dne 04.03.2009 13:18:30:
>
>
>> Hello
>> I am am new to R and any help with the following would be appreciated:
>> I have a list (example attached) and I would like to create a new list
>> which is a filtered version of this list. I.e I would like a list that
>> only contains elements with this value:
>>
>> Chr 10 : 21853562 - 21855482
>>
>
> Lists can have quite complicated structure so here is only a small
> suggestion
>
> lapply(your.list, function(x) x==desired.value)
>
> This shall give you list of logical values if your list has only one
> level.
>
> Something like
>
> pts <- list(x=mtcars[,1], y=mtcars[,2], z=mtcars[,10])
> pts[which(unlist(lapply(pts, function(x) sum(x==4)>0)))]
>
pts[sapply(pts, function(x) sum(x==4)>0)]
will gladly do the same.
vQ