[R] Subsetting list of vectors with list of (boolean) vectors?

Johannes Graumann johannes_graumann at web.de
Fri Apr 13 08:51:50 CEST 2007


Thanks everybody,

Seth's solution is not the general one I was looking for. Both of the others
are. Thanks!

Joh

Liaw, Andy wrote:

> From: Marc Schwartz
>> 
>> On Thu, 2007-04-12 at 18:12 +0200, Johannes Graumann wrote:
>> > Dear Rologists,
>> > 
>> > I'm stuck with this. How would you do this efficiently:
>> > 
>> > > aPGI
>> > [[1]]
>> > [1] "864"  "5576"
>> > 
>> > 
>> > > aPGItest
>> > [[1]]
>> > [1]  TRUE FALSE
>> > 
>> > > result <- [magic box involving subset)
>> > 
>> > > result
>> > [[1]]
>> > [1] "864"
>> > 
>> > Thanks for any hints,
>> > 
>> > Joh
>> 
>> 
>> > lapply(seq(along = length(aPGI)), function(x)
>> > aPGI[[x]][aPGItest[[x]]])
>> [[1]]
>> [1] "864"
> 
> Alternatively:
> 
> R> mapply("[", aPGI, aPGItest, SIMPLIFY=FALSE)
> [[1]]
> [1] "864"
> 
> Cheers,
> Andy
> 
>  
>> 
>> I think that this should be a generic solution for multiple
>> (but common) levels in each list.
>> 
>> HTH,
>> 
>> Marc Schwartz
>> 
>> ______________________________________________
>> 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.
>> 
>> 
>> 
> 
> 
> ------------------------------------------------------------------------------
> Notice:  This e-mail message, together with any attachments,...{{dropped}}
> 
> ______________________________________________
> 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.



More information about the R-help mailing list