[R] String Manipulation- Extract numerical and alphanumerical segment

hadley wickham h.wickham at gmail.com
Fri Feb 5 16:47:22 CET 2010


On Fri, Feb 5, 2010 at 9:29 AM, jim holtman <jholtman at gmail.com> wrote:
> Does this help:
>
>> x <- c("1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12")
>> y <- strsplit(x, '[.]')

Here's another way with the stringr package:

library(stringr)
x <- c("1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12","1234567.z3.abcdef-gh.12")
y <- str_split_fixed(x, '[.]', 4)
y[, 1]
y[, 2]

Hadley



-- 
http://had.co.nz/



More information about the R-help mailing list