[R] selection from a list

jim holtman jholtman at gmail.com
Thu Oct 19 23:39:13 CEST 2006


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 at 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 at 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?



More information about the R-help mailing list