Hi R users following this thread! I evaluated both solutions given by Rui and Arun. Both work very well. Arun's is a little faster.
I did the following time measurements on a large matrix with 2 rows, labelled "InterPro" and "GO", and 88664 columns, labelled with protein IDs. I was interested in selecting those columns (proteins) that share a certain "GO" annotation for molecular function. So here is the time evaluation: * Rui's method: system.time(annos[ , sapply( annos[ "GO", ], function(x) { "GO:0005634" %in% x } ), drop=F ] ) user system elapsed 1.068 0.012 1.079 or system.time(annos[ , unlist( lapply( annos[ "GO", ], function(x) { "GO:0005634" %in% x } ) ), drop=F ]) user system elapsed 0.876 0.000 0.880 * Arun's method: system.time( annos[ , mapply( function(x){any(x=="GO:0005634")}, annos[ "GO", ] ), drop=F ] ) user system elapsed 0.808 0.012 0.826 Thank you Rui and Arun very much for your help and everyone else for your attention! Kind regards! 2012/12/5 arun <smartpink...@yahoo.com> > HI, > Just tweaking my code also gives the same result: > m[,mapply(function(x) any(x=="B"),m),drop=F] > # [,1] [,2] > #[1,] List,2 List,2 > A.K. > > > > ----- Original Message ----- > From: Asis Hallab <asis.hal...@gmail.com> > To: Rui Barradas <ruipbarra...@sapo.pt>; r-help@r-project.org > Cc: > Sent: Tuesday, December 4, 2012 5:26 PM > Subject: Re: [R] How to find matching columns in a matrix of lists? > > Hello, > > m[ , sapply(1:ncol(m), function(j) sapply("B", `%in%`, m[[1 , j]])), drop=F > > ] > > > > It indeed does. > > Thank you very much! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. > > -- Asis Hallab Rothehausstr. 6 - 12 50823 Köln Skype: asis.hallab.cgn Fest (Köln) 42346046 Mobil (O2) 0176 63370211 Fax 01212 - 5 - 30697106 [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org 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.