R Comparison of Character Strings Using Logical Conditions (2 Examples)

In this article, I’ll illustrate how to check for differences in character strings using logical conditions in the R programming language.

Creation of Example Data

x1 <- letters[1:5]        # Two example character strings in R
x1
# [1] "a" "b" "c" "d" "e"
x2 <- letters[3:6]
x2
# [1] "c" "d" "e" "f"

Example 1: Compare Character Strings Using Logical %in% Operator

x1 %in% x2                # Apply %in% operator
# [1] FALSE FALSE  TRUE  TRUE  TRUE

Example 2: Compare Character Strings Using Logical ! %in% Operator

! x1 %in% x2              # Not in x2
# [1]  TRUE  TRUE FALSE FALSE FALSE

Related Tutorials & Further Resources

Here, you may find some further resources on topics such as character strings, vectors, and variables.

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

Menu
Top