setdiff Function in R (Example)

The following R code illustrates how to apply the setdiff() function in the R programming language.

Example Data

We create two vectors containing a different set of numeric values:

vec1 <- c(1, 2, 3, 4, 5)         # Create example data
vec2 <- c(1, 2, 3)

Application of setdiff Function in R

The setdiff function can be applied as follows:

setdiff(vec1, vec2)              # Apply setdiff function
# 4 5

The values 4 and 5 do only exist in vec1, but not in vec2.

Video Examples


By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed