[R] strsplit, keeping delimiters

hadley wickham h.wickham at gmail.com
Sat Jun 14 07:35:38 CEST 2008


Hi all,

Does anyone have a version of strsplit that keeps the string that is
split by.  e.g. from
x <- "A: 123 B: 456 C: 678"

I'd like to get

c("A:", "123 ", "B: ", "456 ", "C: ", 678)

but
strsplit(x, "[A-Z]+:")

gives me
c("", " 123 ", " 456 ", " 678")

Any ideas?

Thanks,

Hadley

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



More information about the R-help mailing list