[R] Managing a list with a list

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Sep 23 08:36:31 CEST 2003

```abunn at mymail.msu.montana.edu wrote:

> OK. Another amateur question.
>
> I have a list with attributes on pine trees, like the stem's location, a logical value set to T if it's alive, some parameters for growth, diameter, etc. The tree list has another list in it which is a new data type for me.
>
> I want to make a new list that retains all the live trees.
> That is where Living == T.
>
> Here's the summary of the list:
>
>
>>summary(tf)
>
>        Length Class  Mode
> id     10     -none- numeric
> x      10     -none- numeric
> y      10     -none- numeric
> A      10     -none- numeric
> NegB   10     -none- numeric
> K      10     -none- numeric
> Age    10     -none- numeric
> DBH    10     -none- numeric
> Living 10     -none- logical
> pSeed  10     -none- list
> TCI    10     -none- numeric
> STA    10     -none- numeric
>
> Here are the living trees.
>
>
>>tf\$Living
>
>  [1] FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
>
> So, here are the ids of the trees I want to retain.
>
>
>>tf\$id[tf\$Living == T]

lapply(tf, "[", tf\$Living)

selects (by indexing with []) those elements from each element of tf,
where tf\$Living is TRUE.

Uwe Ligges

> [1]  2  3  4  5  6  7  9 10
>
> Same with the easting coordinates.
>
>
>>tf\$x[tf\$Living == T] #tf[[2]][tf\$Living == T]
>
> [1] 28 35 18 34 36 92  3 47
>
>
> But when I try to keep the whole list minus the dead trees it returns a list with all the trees living and dead (as I'm sure it is supposed to):
>
> tf[tf\$Living == T]
>
> What am I doing wrong? I'm happy to RTFM, but if the manual in question is section 3.4 of R-lang then I'm still going to need help. I can break it all apart and then concatonate a new list but that seems heavy handed.
>
> Thanks, Andy
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help

```