[R] list operation
Phil Spector
spector at stat.berkeley.edu
Wed Jun 23 23:20:23 CEST 2010
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
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Wed, 23 Jun 2010, 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] "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]]
>
>
More information about the R-help
mailing list