Is there a way in R to check whether a value in one column contains a value within another column?
In the below example, I am trying to see whether values in col2 are contained within the values in col1 (independently within each row) but getting a warning message: "argument 'pattern' has length > 1 and only the first element will be used".
Flag column should show "Yes" for the first/last row and "No" for the 2nd and 3rd rows. Any thoughts on how to resolve would be greatly appreciate.
col1 <- c("R.S.U.L.C","S.I.W","P.U.E","A.E.N")
col2 <- c("R","U","I","N")
df2 <- data.frame(col1,col2)
df2$Flag <- ifelse(grepl(df2$col2,df2$col1),"Yes","No")