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

From: sun <flyhyena_at_yahoo.com.cn>
Date: Wed, 05 Mar 2008 16:57:48 +0100

Thanks all for the prompt answers!!! All works perfectly!

up and running! Thanks!

"jim holtman" <jholtman_at_gmail.com> wrote in message news:644e1f320803050713w8c1a4e6l6b4f9ebe3c00bccf_at_mail.gmail.com...
> This should do it for you:
>
>> x <- c("2564gc", "2367,GH", "2134 JHG")
>> x.sep <- gsub("([[:digit:]]+)[ ,]*([[:alpha:]]+)", "\\1 \\2", x)
>> # now create separate values
>> strsplit(x.sep, " ")
> [[1]]
> [1] "2564" "gc"
>
> [[2]]
> [1] "2367" "GH"
>
> [[3]]
> [1] "2134" "JHG"
>
>>
>
>
> On 3/5/08, sun <flyhyena_at_yahoo.com.cn> wrote:
>> 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.
>>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>
> ______________________________________________
> 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.
>



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 - 16:10:11 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 - 16: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