Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Contains' function [duplicate]

I need to know if there are any functions available in R that allow me to check if one string contains a substring and return a boolean. I've already tried str_detect but that doesn't suit my need.

For example:

string = 12345REFUND4567

and

substring = REFUND

contains(string,substring) would ideally return TRUE since 12345REFUND4567 contains REFUND.

contains(string,substring) is just the format I'd imagine the function to take.

like image 371
Luca Foerster Avatar asked Aug 31 '26 10:08

Luca Foerster


1 Answers

You probably are looking for grepl:

string <- "12345REFUND4567"
grepl("REFUND", string, fixed=TRUE)

[1] TRUE
like image 151
Tim Biegeleisen Avatar answered Sep 03 '26 01:09

Tim Biegeleisen