Here is one solution: > all(unlist(lapply(foo, function(x) c(2,3) %in% x))) [1] TRUE
This doesn't have the restriction of assuming that the components of the list have unique elements, as the original solution does. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Andy Bunn wrote: >Suppose I have a list where I want to extract only the elements that occur >in every component. For instance in the list foo I want to know that the >numbers 2 and 3 occur in every component. The solution I have seems >unnecessarily clunky. TIA, Andy > > foo <- list(x = 1:10, y=2:11, z=1:3) > bar <-unlist(foo) > bartab <- table(bar) > as.numeric(names(bartab)[bartab==length(foo)]) > > [[alternative HTML version deleted]] > >______________________________________________ >[email protected] mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > > > ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
