Re: [R] Are any values in one list contained within a second list

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Sun, 13 Jun 2010 14:25:28 -0400

Hi GL,

Tr this:

# example 1

list1 <- list(letters[1:7])

list1

list2 <- list(c('z','y','x','w','v','u','b'))

list2

mapply(function(x, y) any(x %in% y), list1, list2)

 # example 2

list2 <- list(c('z','y','x','w','v','u','t'))

list2

mapply(function(x, y) any(x %in% y), list1, list2)

HTH,
Jorge

On Sun, Jun 13, 2010 at 2:17 PM, 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.
>

        [[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 Sun 13 Jun 2010 - 18:31:44 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 Sun 13 Jun 2010 - 19:20:30 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