0 votes
1 view
in R Programming by (6.5k points)

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"

1 Answer

0 votes
by (25.3k points)

You can use grepl() function that returns TRUE if a string contains the pattern, and otherwise returns FALSE.

Basic syntax for grepl() function is given below:

grepl(pattern, x, ignore.case = FALSE, perl = FALSE,

  fixed = FALSE, useBytes = FALSE)

 

In your case:

chars <- "test"

value <- "es"

grepl(value, chars)

[1] TRUE

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...