Re: [R] regex sulotion for seperating number and string

From: <vincenzo.2.di-iorio_at_gsk.com>
Date: Wed, 05 Mar 2008 16:08:58 +0100


Hi Sun,

vec <- c("2324gz","2567 HK","3741,BF")

vec1 <- gsub('[^[:digit:]]','',vec)

vec2 <- gsub('[^[:alpha:]]','',vec)  

> vec1

[1] "2324" "2567" "3741"
> vec2

[1] "gz" "HK" "BF"

Cheers
Vincenzo



Vincenzo Luca Di Iorio
Consultant PME User support - GSK R&D Limited

"sun" <flyhyena_at_yahoo.com.cn>
Sent by: r-help-bounces_at_r-project.org
05-Mar-2008 15:51  

To
r-help_at_stat.math.ethz.ch
cc

Subject
[R] regex sulotion for seperating number and string

I have strings contain postcode and letters, some seperated with blank, some
with comma, and some hasn't seperated. eg, "2324gz" "2567 HK" "3741,BF"

I want to seperate the number and letters into two new variables.

I know this should be quite basic question, but searched on regex syntax and
that seems a bit scarey to me, any one can shot me a quick solution on this
particular question?

thanks,
Sun



R-help_at_r-project.org 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.

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Wed 05 Mar 2008 - 15:11:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 05 Mar 2008 - 15:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive