Okay, here is a reproducible example of a possible solution (actually it probably does not do what you want but it's a start for discussion. Note it is actual code and data which is what is needed. ======================================================= str1 <- "abc" str2 <- "abcd" str3 <- "efgh"
grep(str1, str2) grep(str1,str3) ======================================================= Does this help? Without a sample data set I'm guessing plus I'm lousy with text patterns. You almost certainly need someone who knows what they are doing. :) --- On Wed, 6/30/10, Cable, Samuel B Civ USAF AFMC AFRL/RVBXI <samuel.ca...@hanscom.af.mil> wrote: > From: Cable, Samuel B Civ USAF AFMC AFRL/RVBXI <samuel.ca...@hanscom.af.mil> > Subject: Re: [R] What is wrong with this code? > To: r-help@r-project.org > Received: Wednesday, June 30, 2010, 4:22 PM > > > > > Anyway, I still wouldn't mind some advice on > character > > > matching. > > > Thanks. > > > > > If so we need a reproducible example of what you are > doing. > > OK, let's say I have three strings. Str1="abc". > Str2="abcd". > Str3="efgh". > > I want to compare Str1 and Str2 in such a way that R > detects that Str2 > indeed contains Str1. I want something that returns a > "TRUE" value. > Then I want to compare Str1 and Str3 so that R detects that > Str3 does > not contain Str1. I don't want it to give me an error > because it can't > find Str1. I just want to get a "FALSE" value. > Is there a way to do > this that's less messy than what I came up with? > Thanks again. > > ______________________________________________ > R-help@r-project.org > mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, > reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.