Re: [R] list operation

From: <Bill.Venables_at_csiro.au>
Date: Thu, 24 Jun 2010 09:34:15 +1000

Here is an alternative:

> lst <- list(m = c('a','b','c'), n = c('c','a'), l = c('a','bc'))
> set <- c("a", "c")

> (w <- sapply(lst, function(x) all(set %in% x)))

    m n l
 TRUE TRUE FALSE
> names(w)[w]

[1] "m" "n"   

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] On Behalf Of Henrique Dallazuanna Sent: Thursday, 24 June 2010 9:21 AM
To: Yuan Jian
Cc: r-help_at_r-project.org
Subject: Re: [R] list operation

Try this:

 lst[colSums(mapply('%in%', list(set), lst)) == 2]

On Wed, Jun 23, 2010 at 10:35 AM, Yuan Jian <jayuan2008_at_yahoo.com> 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] "c" "a"
> $l
> [1] "a" "bc"
>
> how can I get list elements that include a given subset? for example, for
> given subset {'a','c'}, the answer should be 'm' and 'n'.
>
> thanks
> Yu
>
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help_at_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.
>
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_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.
Received on Wed 23 Jun 2010 - 23:37:40 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jun 2010 - 01:10:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive