[R] using grep

David Winsemius dwinsemius at comcast.net
Fri Feb 26 23:13:59 CET 2010


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 York", x, value = TRUE))
[1] "722" "20"



> but that is not what i want, I want the output to be
>
> 722,20
>



Aside from being a character vector without commas, it seemed pretty  
close.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list