how to write contains function in R

Hi Team,

How to write if find or contains function in R, and then created new column as page.

Page :-
Page :-
If page contains " THEN Page = "Studio";
if Page contains " THEN Page = "PEN";
else "blank";

You can use the grepl function from base R or the str_detect function from the stringr package to return TRUE or FALSE whether a string contains another string. With that, a standard if and else structure should get you what you need.

Page = ""

grepl("", Page)
#> [1] TRUE

#> Warning: package 'stringr' was built under R version 3.5.3
str_detect(Page, "")
#> [1] TRUE

Created on 2019-11-05 by the reprex package (v0.3.0.9000)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.