I am searching through a column to find a pattern,
reg <- regexpr("pattern", Data$column1)
View(reg)
reg gives me some numbers as the following:
[1] 43 15 2 11
[19] 22 28 20 11
[37] 32 11 32 20
but I want reg
to be 0 or 1 based on whether "pattern" has been found or not in Data$column1
.
When I used grepl,
reg <- grepl("pattern", Data$column1)
View(reg)
I only got TRUE values in reg
. Not FALSE values. But I want both in the column. If it finds the pattern store TRUE in reg
if not store FALSE.
How can this be accomplished?