[R] ifelse and wildcard matching
Jennifer Brea
brea at fas.harvard.edu
Sun Dec 6 21:05:01 CET 2009
Hi,
I'm trying to create a new variable using the following code:
A$B2<-ifelse(A$B %in% "EDUCATION","EDUCATION",NA)
The problem is, I want the new variable to be labeled "EDUCATION" if the
original *contains* "EDUCATION", not of it is an exact match. I've done
a lot of searching on wild cards and the like, and the only function
I've found that does this kind of matching is grep(), which I don't
think I can use here, since it subsets the original data.
Any ideas?
Thanks!
More information about the R-help
mailing list