[R] Spliting a text

Michael Hannon jm_hannon at yahoo.com
Thu Aug 5 00:47:36 CEST 2010





----- Original Message ----
> From: Megh Dal <megh700004 at yahoo.com>
> To: r-help at stat.math.ethz.ch
> Sent: Wed, August 4, 2010 4:04:06 AM
> Subject: [R] Spliting a text
> 
> Hi, I want to split a text to seperate numerical and non-numerical portions of  
>that. For example suppose I have a text "abc 3456" and I want to split in 2  
>parts like "abc" & "3456".
> 
> Is there any function to do  that?
> 
> Thanks,

> full.string <- "abc 3456"
> letter.part <- sub("^([[:alpha:]]+).*$", "\\1", full.string); letter.part
[1] "abc"
> numeric.part <- sub("^[^0-9]+(.*)$", "\\1", full.string); numeric.part
[1] "3456"
>



More information about the R-help mailing list