To find the characters in the first string that are not present in the second string in R, you can use functions like setdiff and strsplit.
In this example,
str1
and str2
with different values.strsplit
function.setdiff
function to find the characters of str1
vector that are not present in str2
vector.# Find Characters Not Present in Second String
str1 <- 'Hello World'
str2 <- 'apple'
chars1 <- strsplit(str1, '')[[1]]
chars2 <- strsplit(str2, '')[[1]]
diff <- setdiff(chars1, chars2)
result <- paste(diff, collapse = '')
cat('Characters not present in second string:', result, '
')
Characters not present in second string: Ho Word
In this tutorial, we learned How to find the Characters in the First String that are not Present in the Second String in R language with well detailed examples.