hi,
using the example in the grep help:
txt <- c("arm","foot","lefroo",
"bafoobar")
i <- grep("foo",txt); i
[1] 2 4
but how can i get the negation (1,3) when looking for 'foo'?
thanks,
m.
?setdiff e.g.,> txt <- c("arm","foot","lefroo", "bafoobar") > i <- grep("foo",txt); i[1] 2 4> setdiff(seq(length(txt)),grep("foo",txt))[1] 1 3>Jim __________________________________________________________ James Holtman "What is the problem you are trying to solve?" Executive Technical Consultant -- Convergys Labs james.holtman at convergys.com +1 (513) 723-2929 Marcus Leinweber <leinwebe at eva.mpg.de> To: "'r-help at stat.math.ethz.ch'" <r-help at stat.math.ethz.ch> Sent by: cc: r-help-bounces at stat.m Subject: [R] grep negation ath.ethz.ch 06/23/2005 08:59 hi, using the example in the grep help: txt <- c("arm","foot","lefroo", "bafoobar") i <- grep("foo",txt); i [1] 2 4 but how can i get the negation (1,3) when looking for 'foo'? thanks, m. ______________________________________________ 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
try this:
seq(along = txt)[-i]
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Marcus Leinweber" <leinwebe at eva.mpg.de>
To: <r-help at stat.math.ethz.ch>
Sent: Thursday, June 23, 2005 2:59 PM
Subject: [R] grep negation
> hi,
>
> using the example in the grep help:
> txt <- c("arm","foot","lefroo",
"bafoobar")
> i <- grep("foo",txt); i
> [1] 2 4
>
> but how can i get the negation (1,3) when looking for 'foo'?
>
> thanks,
> m.
>
> ______________________________________________
> 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
>
If all you need to do is extract the subset of elements of txt that do not contain 'foo', then txt[-i] will do the job. Provided that at east one element of txt contains 'foo', that is. -Don At 2:59 PM +0200 6/23/05, Marcus Leinweber wrote:>hi, > >using the example in the grep help: >txt <- c("arm","foot","lefroo", "bafoobar") >i <- grep("foo",txt); i >[1] 2 4 > >but how can i get the negation (1,3) when looking for 'foo'? > >thanks, >m. > >______________________________________________ >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-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA