Find the elements of a vector that are not in another vector in R
Two vectors can hold some values common. This article discusses how can we find set difference of these vectors i.e. display elements which are present in one vector but not in the other.
If we want all the elements of a vector that are not in another vector then we can use setdiff() method in R. It takes two vectors and returns a new vector with the elements of the first vector that are not present in the second vector.
- Create first vector
- Create second vector
- Find set difference
- Store this in another vector
- Display result
 1 3 29 9 71
 “rahul” “rohan” “rohit” “kapil”