[R] grep question

jim holtman jholtman at gmail.com
Fri Sep 1 03:19:39 CEST 2006


Forget the last reply.  I left the 'value=TRUE' off the grep.

> x <- c('xxxFarrahxxx' ,'more than last time', 'some Common numbers', 'last one')
> setdiff(x, grep('Farrah|Common', x, value=TRUE))
[1] "more than last time" "last one"
> ForC <- grep('Farrah|Common', x)
> x[setdiff(seq(along=x), ForC)]
[1] "more than last time" "last one"
>


On 8/31/06, jim holtman <jholtman at gmail.com> wrote:
> You have to be careful if the strings are embedded:
>
> > x <- c('xxxFarrahxxx' ,'more than last time', 'some Common numbers', 'last one')
> > setdiff(x, grep('Farrah|Common', x))  # not correct
> [1] "xxxFarrahxxx"        "more than last time" "some Common numbers"
> "last one"
> > ForC <- grep('Farrah|Common', x)
> > x[setdiff(seq(along=x), ForC)]
> [1] "more than last time" "last one"
> >
>
>
> On 8/31/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > Or using the same x:
> >
> > > setdiff(x, grep("Farrah|Common", x, value = TRUE))
> > [1] "more" "last"
> >
> > On 8/31/06, jim holtman <jholtman at gmail.com> wrote:
> > > This finds the matching indices of Farrah and Common and then create a
> > > set that does not include them:
> > >
> > > > x <- c('Farrah', 'more', 'Common', 'last')
> > > > got.F <- grep('Farrah',x)
> > > > got.C <- grep('Common', x)
> > > > not.ForC <- setdiff(seq(along=x), c(got.F, got.C))
> > > > x[not.ForC]
> > > [1] "more" "last"
> > > >
> > >
> > >
> > > On 8/31/06, Bob Green <bgreen at dyson.brisnet.org.au> wrote:
> > > >
> > > > I am hoping for some advice as to how to modify the following syntax, so
> > > > that instead of saving all records which refer to Farrah, I select all
> > > > instances that do not include Farrah, or the word Coolum.
> > > >
> > > >
> > > > test <- read.csv("c:\\newdat.csv", as.is=TRUE, header=T)
> > > > sure <- test[grep('Farrah', paste(test$V3.HD, test$V3.LP, test$V3.TD)),]
> > > > write.csv(sure,"c:/farrah4.csv")
> > > >
> > > >
> > > > Any assistance is appreciated,
> > > >
> > > > regards
> > > >
> > > > Bob  Green
> > > >
> > > > ______________________________________________
> > > > R-help at stat.math.ethz.ch 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.
> > > >
> > >
> > >
> > > --
> > > Jim Holtman
> > > Cincinnati, OH
> > > +1 513 646 9390
> > >
> > > What is the problem you are trying to solve?
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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 at stat.math.ethz.ch 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.
> >
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list