Re: [R] list operation

2010-06-23 Thread Bill.Venables
UE TRUE FALSE > names(w)[w] [1] "m" "n" -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Sent: Thursday, 24 June 2010 9:21 AM To: Yuan Jian Cc: r-help@r-project.org Subject: Re: [R] list

Re: [R] list operation

2010-06-23 Thread Henrique Dallazuanna
Try this: lst[colSums(mapply('%in%', list(set), lst)) == 2] On Wed, Jun 23, 2010 at 10:35 AM, Yuan Jian wrote: > Hi, > > it seems a simple problem, but I can not find a clear way. > I have a list: > lst=list(m=c('a','b','c'),n=c('c','a'),l=c('a','bc')) > > lst > $m > [1] "a" "b" "c" > $n > [1]

Re: [R] list operation

2010-06-23 Thread Joris Meys
Another variation on the same theme : lst=list(m=c('a','b','c'),n=c('c','a'),l=c('a','bc')) set <- c('a','c') f <-function(lst,set) sapply(lst,function(x) sum(set %in% x)==length(set) ) i <- f(lst,set) names(i[i]) Doesn't serve anybody but keeps my mind fresh. For long lists, you might benefit

Re: [R] list operation

2010-06-23 Thread Peter Alspach
Tena koe Yu One possibility: lst[sapply(lst, function(x) length(x[x%in% c('a','c')])==2)] HTH ... Peter Alspach > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of Yuan Jian > Sent: Thursday, 24 June 2010 1:35 a.m. > To: r-hel

Re: [R] list operation

2010-06-23 Thread William Dunlap
> lst <- list(m=c('a','b','c'),n=c('c','a'),l=c('a','bc')) > f <- function(list, set) vapply(lst, function(el)all(is.element(set, el)), FUN.VALUE=logical(1)) > # if you have an old version of R use as.logical(sapply(...)) > # instead of vapply(..., FUN.VALUE=logical(10) > i <- f(lst, c(

Re: [R] list operation

2010-06-23 Thread Phil Spector
Yuan - There may be faster ways, but names(lst)[sapply(lst,function(i)'a' %in% i && 'c' %in% i)] seems to do what you want. - Phil Spector Statistical Computing Facility D