Please share your sample data as copy/pasteable R syntax, e.g. dput(your_data[1:4, ]) to make a copy/pasteable version of the first 4 rows. It's very hard to test a solution on a picture of data.
- Gregor Thomas
Also, you've asked quite a few questions, but only Accepted a single answer. I'd suggest going back to some of your old questions and accepting answers that worked--it's a nice way to keep the site tidy (so people know when questions are resolved) and to thank the answerers.
- Gregor Thomas
Here's a start, though not exactly the output you present (which is, btw, inconsistent with the text of your question): cbind(dat, lapply(setNames(nm=c("C","L")), function(z) grepl(paste0("\\b",z,"\\b"), dat$Data)))
- r2evans
or perhaps better cbind(dat, lapply(setNames(nm=c("C","L")), function(z) ifelse(grepl(paste0("\\b",z,"\\b"), dat$Data),z,NA)))
- r2evans
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
dput(your_data[1:4, ])
to make a copy/pasteable version of the first 4 rows. It's very hard to test a solution on a picture of data. - Gregor Thomascbind(dat, lapply(setNames(nm=c("C","L")), function(z) grepl(paste0("\\b",z,"\\b"), dat$Data)))
- r2evanscbind(dat, lapply(setNames(nm=c("C","L")), function(z) ifelse(grepl(paste0("\\b",z,"\\b"), dat$Data),z,NA)))
- r2evans