[R] grep question

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 1 02:31:29 CEST 2006


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.
>



More information about the R-help mailing list