Skip to content

Extracting non-matching elements of one vector from another

3 messages · Dan Abner, Bert Gunter, Duncan Murdoch

#
Hi all,

I have 2 vectors and need to extract only the elements from v2 that do not
appear in v1. What is the most efficient way to do this?

In the example below, I need to extract "var1".

v1<-"b0"
v2<-c("b0","var1")

Thanks,

Dan
#
?setdiff
## It's a wrapper for ?match

setdiff(v2,v1)

You should go through an R tutorial or two to learn about such handy
basic functionality.

-- Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sat, Dec 31, 2016 at 10:36 AM, Dan Abner <dan.abner99 at gmail.com> wrote:
#
On 31/12/2016 1:36 PM, Dan Abner wrote:
setdiff(v2, v1)

Duncan Murdoch