0

Possible Duplicate:
Access atomic vectors shown by Filter(is.atomic, eq) in R

I am wondering if there is any option / function to search for a variable in all objects of a list. So basically the functionality of which(some_vector == "ABC") on a list. Is this possible somehow?

Thank you in advance!

Community
  • 1
  • 1
bontus
  • 437
  • 1
  • 5
  • 9
  • 1
    You need to provide us with a little example to make clear what you want, see also : http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Joris Meys Feb 03 '12 at 14:13
  • well, if the list components are named then you can subset the list based on the name for example mylist[["ABC"]] – richiemorrisroe Feb 03 '12 at 14:13
  • 2
    Check also the answers on [recursively going through lists](http://stackoverflow.com/questions/8754475/access-atomic-vectors-shown-by-filteris-atomic-eq-in-r/8758317#8758317) – Joris Meys Feb 03 '12 at 14:15
  • ok, let my list be a = list() a[[1]] = c("ABC","CDE","DEF") a[[2]] = "---" a[[3]] = "XYZ" I want to return the index of the vector containing the string "ABC", so in this case 1. – bontus Feb 03 '12 at 14:15
  • @JorisMeys, thank you very much for the link, I think I got the solution: which(rapply(a,function(x) grep("ABC",x))==1) – bontus Feb 03 '12 at 14:23
  • @bontus : you can add that as an answer to your own question for future reference. Cheers. – Joris Meys Feb 03 '12 at 14:40

0 Answers0