mike mike - 1 month ago 7
R Question

Test if characters in string in R

I'm trying to determine if a string is a subset of another string. For example:

chars <- "test"
value <- "es"


I want to return TRUE if "value" appears as part of the string "chars". In the following scenario, I would want to return false:

chars <- "test"
value <- "et"

smu smu
Answer

Use the grepl function

grepl(value, chars)
# TRUE
Comments