Compare two character vectors in R
In this article, we will discuss how to compare two character vectors in R Programming Language.
Method 1: Using %in%
This operator is used to find the elements present in one vector with respect to the second vector
Syntax: vector1 %in% vector2
Return type: It returns boolean values corresponding to the elements in a vector
- It returns true, if corresponding element is present in vector 2
- It returns false, if corresponding element is not present in vector 2.
 TRUE FALSE FALSE
Method 2: Using intersect()
intersect() function is used to return the common element present in two vectors. Thus, the two vectors are compared, and if a common element exists it is displayed.
Method 3: Using setdiff()
This function returns the elements present in vector1 but not present in vector2 and vice versa. Thus, two vectors are first compared for similarity, and elements are displayed accordingly.
 "sravya" "navya"  "sravan" "deepika"