Try this:
> library(gsubfn)
> x <- "A: 123 B: 456 C: 678"
> strapply(x, "[^ :]+[ :]|[^ :]+$")
[[1]]
[1] "A:" "123 " "B:" "456 "
"C:" "678"
and check out the gsubfn home page at:
http://gsubfn.googlecode.com
On Sat, Jun 14, 2008 at 1:35 AM, hadley wickham <h.wickham at gmail.com>
wrote:> 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/
>
> ______________________________________________
> 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.
>