+5 votes
in Programming Languages by (40.5k points)
What R function should I use to check if a substring or a character is present in a string?

1 Answer

+1 vote
by (350k points)
selected by
 
Best answer

The grepl() function can be used to check if a character or a substring is present in a string.

Here is an example:

> a="Hello world!!"
> grepl('Hello', a)
[1] TRUE
> grepl('Hello1', a)
[1] FALSE
> grepl('H', a)
[1] TRUE
> grepl('h', a)
[1] FALSE


...