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

1 Answer

0 votes
by (33.7k points)

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

...