Odp: Filtering R lists
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