Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Stephen Tucker
Thanks guys for the suggestions guys- I come across this problem a lot but now I have many solutions. Thank you, Stephen --- Peter Dalgaard <[EMAIL PROTECTED]> wrote: > Peter Dalgaard wrote: > > Stephen Tucker wrote: > > > >> Dear R-helpers, > >> > >> Does anyone know how to use regular exp

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Tony Plate
I use regexpr() instead of grep() in cases like this, e.g.: x2[regexpr("exclude",x2)==-1] (regexpr returns a vector of the same length as character vector given it, so there's no problem with it returning a zero length vector) -- Tony Plate Peter Dalgaard wrote: > Stephen Tucker wrote: >> Dear

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Peter Dalgaard
Peter Dalgaard wrote: > Stephen Tucker wrote: > >> Dear R-helpers, >> >> Does anyone know how to use regular expressions to return vector elements >> that don't contain a word? For instance, if I have a vector >> x <- c("seal.0","seal.1-exclude") >> I'd like to get back the elements which do n

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread jim holtman
Find the ones that match and then remove them from the full set with 'setdiff'. > x <- c("seal.0","seal.1-exclude") > x.match <- grep("exclude", x) # find matches > x.match [1] 2 > setdiff(seq_along(x), x.match) # exclude the matches [1] 1 > On 4/25/07, Peter Dalgaard <[EMAIL PROTECTED]> wrote

Re: [R] regular expressions with grep() and negative indexing

2007-04-25 Thread Peter Dalgaard
Stephen Tucker wrote: > Dear R-helpers, > > Does anyone know how to use regular expressions to return vector elements > that don't contain a word? For instance, if I have a vector > x <- c("seal.0","seal.1-exclude") > I'd like to get back the elements which do not contain the word "exclude", > us

[R] regular expressions with grep() and negative indexing

2007-04-25 Thread Stephen Tucker
Dear R-helpers, Does anyone know how to use regular expressions to return vector elements that don't contain a word? For instance, if I have a vector x <- c("seal.0","seal.1-exclude") I'd like to get back the elements which do not contain the word "exclude", using something like (I know this doe