Re: [R] selection from a list

From: jim holtman <jholtman_at_gmail.com>
Date: Thu 19 Oct 2006 - 21:39:13 GMT

try this:

z <- lapply(yourList, function(x){

    if (x$error < 0.1) return(x) # your test condition     else return(NULL)
})
# now delete the NULLs
z <- z[unlist(lapply(z, length) != 0)]

On 10/19/06, Weiwei Shi <helprhelp@gmail.com> wrote:
> hi,
>
> i have a list which looks like this:
>
> $ :List of 3
> ..$ network: chr "xenobiotic_metabolism_1"
> ..$ error : num 0.134
> ..$ table : int [1:2, 1:2] 5 15 4 118
> .. ..- attr(*, "dimnames")=List of 2
> .. .. ..$ : chr [1:2] "0" "1"
> .. .. ..$ : chr [1:2] "0" "1"
> .. ..- attr(*, "class")= chr "table"
> $ :List of 3
> ..$ network: chr "dd_inflammation_r_genes"
> ..$ error : num 0.0775
> ..$ table : int [1:2, 1:2] 8 10 1 123
> .. ..- attr(*, "dimnames")=List of 2
> .. .. ..$ : chr [1:2] "0" "1"
> .. .. ..$ : chr [1:2] "0" "1"
> .. ..- attr(*, "class")= chr "table"
> $ :List of 3
> ..$ network: chr "ng_protein_folding_short_genes"
> ..$ error : num 0.239
> ..$ table : int [1:2, 1:2] 6 31 3 102
> .. ..- attr(*, "dimnames")=List of 2
> .. .. ..$ : chr [1:2] "0" "1"
> .. .. ..$ : chr [1:2] "0" "1"
> .. ..- attr(*, "class")= chr "table"
>
>
> I am wondering how to select the component whose $error is, say, less than 0.1?
>
> I can do unlist and transform it into a data.frame to do selection,
> but I just want to learn if there is a way to do the list selection.
>
> thanks,
>
> --
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Fri Oct 20 07:46:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 19 Oct 2006 - 22:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.