Case-Insensitive comparison
In this example we have compare two string in case Insensitive.
R
# Define two strings(str1 and str2) String_1 <- "w3wiki" String_2 <- "w3wiki" # tolower() to convert string to lower case ans <- tolower (String_1) == tolower (String_2) # Conditional if statement to check whether ans is true or not if (ans) { cat ( "The strings are equal" ) } else { cat ( "The strings are not equal" ) } |
Output:
The strings are equal
- Since, the case are not equal for both the string so we made both the string in lower case using tolower() function.
- Output is true i.e. “The strings are equal” as both the string have now become equal.
Program to Compare two Strings in R
String comparison is a common operation where two strings are compared in a case sensitive manner and check whether they are equal or not. In this article you will learn the various way in which you can compare two string in R language.
Contact Us