Robin Hankin wrote:
> check.for.inclusion <- function(subsets){
> out <- rep(FALSE,length(subsets)-1)
> for(i in 1:(length(subsets)-1)){
> out[i] <- all(subsets[[i+1]] %in% subsets[[i]])
> }
> return(all(out))
> }
>
>
> how to do it elegantly and/or quickly?
>
My first thought was to rewrite that function but drop out if it didnt
match. But then...
Assuming the first list element is the longest, then its a one liner:
check2 <- function(l){
length(unique(unlist(l))) == length(l[[1]])
}
- basically the set of everything in all the elements is the first
element, so take unique(everything) and see if its the same size as the
first element. Unless I've missed something...
I'd call that elegant, it may also be quicker!
Baz
______________________________________________
[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