Re: [R] using grep

2010-02-28 Thread kMan
Then use strsplit() instead. KeithC. -Original Message- From: kayj [mailto:kjaj...@yahoo.com] Sent: Friday, February 26, 2010 1:02 PM To: r-help@r-project.org Subject: Re: [R] using grep Hi , I have tried gsub(".*York(\\d+).*", "\\1", grep("New York&

Re: [R] using grep

2010-02-27 Thread Gabor Grothendieck
alf Of kayj >> Sent: Friday, February 26, 2010 11:27 AM >> To: r-help@r-project.org >> Subject: [R] using grep >> >> >> Hi All, >> >> I have a character vector with naems of cities in the us. I need to >> extract >> the number that appear

Re: [R] using grep

2010-02-27 Thread Greg Snow
ct.org [mailto:r-help-boun...@r- > project.org] On Behalf Of kayj > Sent: Friday, February 26, 2010 11:27 AM > To: r-help@r-project.org > Subject: [R] using grep > > > Hi All, > > I have a character vector with naems of cities in the us. I need to > extract > the numb

Re: [R] using grep

2010-02-26 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of kayj > Sent: Friday, February 26, 2010 12:02 PM > To: r-help@r-project.org > Subject: Re: [R] using grep > > > Hi , > > I have tried >

Re: [R] using grep

2010-02-26 Thread David Winsemius
On Feb 26, 2010, at 3:02 PM, kayj wrote: Hi , I have tried gsub(".*York(\\d+).*", "\\1", grep("New York", x, value = TRUE)) and outputs "P New York722AZ" "K New York20" Strange: > x<-c("P Los Angeles44AZ", "P New York722AZ", "K New York20") > > gsub(".*York(\\d+).*", "\\1", grep("New Yo

Re: [R] using grep

2010-02-26 Thread Henrique Dallazuanna
What is your R version? Install the most recent R version (2.10.1). On Fri, Feb 26, 2010 at 5:02 PM, kayj wrote: > > Hi , > > I have tried > > gsub(".*York(\\d+).*", "\\1", grep("New York", x, value = TRUE)) > > and outputs > >  "P New York722AZ" "K New York20" > but that is not what i want, I w

Re: [R] using grep

2010-02-26 Thread kayj
Hi , I have tried gsub(".*York(\\d+).*", "\\1", grep("New York", x, value = TRUE)) and outputs "P New York722AZ" "K New York20" but that is not what i want, I want the output to be 722,20 -- View this message in context: http://n4.nabble.com/using-grep-tp1571102p1571251.html Sent fro

Re: [R] using grep

2010-02-26 Thread Henrique Dallazuanna
Try this: gsub(".*York(\\d+).*", "\\1", grep("New York", x, value = TRUE)) On Fri, Feb 26, 2010 at 3:27 PM, kayj wrote: > > Hi All, > > I have a character vector with naems of cities in the us. I need to extract > the number that appear after the word "New York", for example, > > x<-c("P Los Ang

[R] using grep

2010-02-26 Thread kayj
Hi All, I have a character vector with naems of cities in the us. I need to extract the number that appear after the word "New York", for example, x<-c("P Los Angeles44AZ", "P New York722AZ", "K New York20") I want the results to be 722, 20 cab I use the grep function, if so how? I apprecia

Re: [R] Using grep to determine value of last letter...

2009-10-19 Thread Gabor Grothendieck
Here are several ways to find the last character in a string: > x <- "abc" > substring(x, nchar(x)) [1] "c" > sub(".*(.)", "\\1", x) [1] "c" > library(gsubfn) > strapply(x, ".$")[[1]] [1] "c" On Mon, Oct 19, 2009 at 3:52 PM, Jason Rupert wrote: > I am currently being defeated by grep.  I am a

Re: [R] Using grep to determine value of last letter...

2009-10-19 Thread Bert Gunter
stLetter <- substr(yourstring, n, n) Bert Gunter Genentech Nonclinical Biostatistics -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Rupert Sent: Monday, October 19, 2009 12:52 PM To: R-help@r-project.org Subject: [R] Us

[R] Using grep to determine value of last letter...

2009-10-19 Thread Jason Rupert
I am currently being defeated by grep. I am attempting to determine the value of the last letter of a character string. An example of my data set is shown below. Regarding the codes, I would like to identify the value of the last character and then take the appropriate action, e.g. If the

Re: [R] Using grep() to subset lines of text

2008-12-02 Thread Uwe Ligges
ppaarrkk wrote: I have two vectors, a and b. b is a text file. I want to find in b those elements of a which occur at the beginning of the line in b. I have the following code, but it only returns a value for the first value in a, but I want both. Any ideas please. a = c(2,3) b = NULL b[1] =

Re: [R] Using grep() to subset lines of text

2008-11-29 Thread Gabor Grothendieck
Try this. For each character x in s, if "x" is punctuation it is replaced with "\\x" otherwise with "[x]" : library(gsubfn) gsubfn('.', ~ if (any(grep("[[:punct:]]", x))) paste0('\\', x) else paste0('[', x, ']'), s) See http://gsubfn.googlecode.com On Sat, Nov 29, 2008 at 10:09 PM, Stavros Mac

Re: [R] Using grep() to subset lines of text

2008-11-29 Thread Stavros Macrakis
But I don't want to ignore all regexp's -- I want to build a regexp which contains string components which are parameters. -s On Sat, Nov 29, 2008 at 6:51 PM, Gabor Grothendieck <[EMAIL PROTECTED] > wrote: > grep has a fixed = TRUE argument if you want to ignore all regexp's. > > On

Re: [R] Using grep() to subset lines of text

2008-11-29 Thread Gabor Grothendieck
grep has a fixed = TRUE argument if you want to ignore all regexp's. On Sat, Nov 29, 2008 at 3:55 PM, Stavros Macrakis <[EMAIL PROTECTED]> wrote: > Hmm, this brings up an interesting question. What if the string I'm looking > for contains escape characters? For example, grep( paste( "^", "(ab)"

Re: [R] Using grep() to subset lines of text

2008-11-29 Thread Stavros Macrakis
Hmm, this brings up an interesting question. What if the string I'm looking for contains escape characters? For example, grep( paste( "^", "(ab)" ), c("ab","(ab)") ) => c(1), not c(2). I couldn't find an equivalent to Emacs's regexp-quote, which would let me write regexp.quote("(ab)") => "\\(ab\

Re: [R] Using grep() to subset lines of text

2008-11-29 Thread Gabor Grothendieck
Try this: > a <- 2:3 > b <- c("aaa 2 aaa", "2 aaa", "3 aaa", "aaa 3 aaa") > > re <- paste("^(", paste(a, collapse = "|"), ")", sep = "") > re [1] "^(2|3)" > grep(re, b, value = TRUE) [1] "2 aaa" "3 aaa" On Sat, Nov 29, 2008 at 7:00 AM, ppaarrkk <[EMAIL PROTECTED]> wrote: > > I have two vectors, a

[R] Using grep() to subset lines of text

2008-11-29 Thread ppaarrkk
I have two vectors, a and b. b is a text file. I want to find in b those elements of a which occur at the beginning of the line in b. I have the following code, but it only returns a value for the first value in a, but I want both. Any ideas please. a = c(2,3) b = NULL b[1] = "aaa 2 aaa" b[2] =

Re: [R] Using grep

2008-10-08 Thread Ted Harding
On 08-Oct-08 15:19:02, mentor_ wrote: > Hi, > I have a vector A with (200, 201, 202, 203, 204, ... 210) and > a vector B with (201, 204, 209). > Now I would like to get the position in vector A matches with > the entries in vector B > So what I want to have is the following result: > [1] 2 5 10 Fi

Re: [R] Using grep

2008-10-08 Thread Doran, Harold
A <- seq(200,210,1) B <- c(201,204,209) which(A %in% B) > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of mentor_ > Sent: Wednesday, October 08, 2008 11:19 AM > To: r-help@r-project.org > Subject: [R] Using grep > >

Re: [R] Using grep

2008-10-08 Thread Erin Hodgess
Here is a possible solution: > A [1] 200 201 202 203 204 205 206 207 208 209 210 > B [1] 201 204 209 > which(!is.na(match(A,B))) [1] 2 5 10 > Hope this helps, Sincerely, Erin On Wed, Oct 8, 2008 at 10:19 AM, mentor_ <[EMAIL PROTECTED]> wrote: > > Hi, > > I have a vector A with (200, 201, 202

Re: [R] Using grep

2008-10-08 Thread Christos Hatzis
which(A %in% B) -Christos > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of mentor_ > Sent: Wednesday, October 08, 2008 11:19 AM > To: r-help@r-project.org > Subject: [R] Using grep > > > Hi, > > I have a vecto

[R] Using grep

2008-10-08 Thread mentor_
Hi, I have a vector A with (200, 201, 202, 203, 204, ... 210) and a vector B with (201, 204, 209). Now I would like to get the position in vector A matches with the entries in vector B So what I want to have is the following result: [1] 2 5 10 I tried the following: grep(B, A) grep(c(B), A) A