You can try the following expression:
x <- "weg|laan" # or paste(c("weg", "laan"), collapse="|")
df$test <- ifelse(grepl(x, df_weg), 1, 0)
|
in a regex
means "or"
As a more direct way, thanks to @DavidArenburg, as you need a 0/1 output, you can just convert the logical result of grepl
to integer:
as.integer(grepl("weg|laan", df_weg))
or, if you want to do codegolfing (but less good pratice):
+grepl("weg|laan", df_weg)