[R] Are any values in one list contained within a second list
Phil Spector
spector at stat.berkeley.edu
Sun Jun 13 21:25:24 CEST 2010
I think the simplest way is to translate the English
directly :-)
> list1 = c('a','b','c','d','e','f','g')
> list2 = c('z','y','x','w','v','u','b')
> any(list2 %in% list1)
[1] TRUE
> list2 = c('z','y','x','w','v','u','t')
> any(list2 %in% list1)
[1] FALSE
- Phil Spector
Statistical Computing Facility
Department of Statistics
UC Berkeley
spector at stat.berkeley.edu
On Sun, 13 Jun 2010, GL wrote:
>
> Silly question, but, can I test to see if any value of list a is contained in
> list b without doing a loop? A loop is easy enough, but wanted to see if
> there was a cleaner way. By way of example:
>
> List 1: a, b, c, d, e, f, g
>
> List 2: z, y, x, w, v, u, b
>
> Return true, since both lists contain b
>
> List 1: a, b, c, d, e, f, g
>
> List 2: z, y, x, w, v, u, t
>
> Return false, since the lists have no mutual values
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Are-any-values-in-one-list-contained-within-a-second-list-tp2253637p2253637.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list