Re: [R] finding those elements of listA that are found in listB

2015-09-17 Thread Adams, Jean
John, The intersect() function may help you. For example: listA <- sort(sample(10, 5)) listB <- sort(sample(10, 5)) both <- intersect(listA, listB) > listA [1] 2 4 7 8 9 > listB [1] 1 2 3 8 10 > both [1] 2 8 Jean On Wed, Sep 16, 2015 at 9:43 PM, John Sorkin

Re: [R] finding those elements of listA that are found in listB

2015-09-16 Thread Richard M. Heiberger
I think you are looking for match or %in% (which is a based on match) > a <- sample(12) > b <- c(1, 3, 5, 11, 17) > a [1] 10 8 1 4 7 3 6 11 2 12 5 9 > b [1] 1 3 5 11 17 > [1] 1 > match(a, b) [1] NA NA 1 NA NA 2 NA 4 NA NA 3 NA > match(a, b, 0) [1] 0 0 1 0 0 2 0 4 0 0 3 0 >

[R] finding those elements of listA that are found in listB

2015-09-16 Thread John Sorkin
I have two structures. I think they are lists, but I am not sure. Both structures contain integers. I am trying to find those members of list b that are found in list a. I have tried to perform the search using grep, but I get an error. Please see code below. I would appreciate knowing how to