Johannes Graumann
2007-Apr-12 16:12 UTC
[R] Subsetting list of vectors with list of (boolean) vectors?
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
Marc Schwartz
2007-Apr-12 16:43 UTC
[R] Subsetting list of vectors with list of (boolean) vectors?
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" I think that this should be a generic solution for multiple (but common) levels in each list. HTH, Marc Schwartz
Seth Falcon
2007-Apr-12 16:45 UTC
[R] Subsetting list of vectors with list of (boolean) vectors?
Johannes Graumann <johannes_graumann at web.de> writes:> 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 <- aPGI[aPGItest[[1]]]>> result > [[1]] > [1] "864" >+ seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org