If I have these strings:
dat <- data.frame(xxs = c("PElookx.PElookxstd","POaftGx.POlookGxstd"))
how can I create a new variable where for instance if the string contains PE I want NOW or PO I would get LATER
newxxs <- (`NOW`,`LATER`)
I kind of know how to use grep to do this:
dat$newxss <- NA
dat$newxss[grep("PE",dat$xxs)] <- "NOW"
dat$newxss[grep("PO",dat$xxs)] <- "LATER"
Is there a easier way than lots of greps? As I will have to do this for multiple bits of strings for the same new column and for many new columns.
PEorPO?