[R] strsplit, keeping delimiters

From: hadley wickham <h.wickham_at_gmail.com>
Date: Sat, 14 Jun 2008 00:35:38 -0500


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.
Received on Sat 14 Jun 2008 - 05:48:49 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 Sat 14 Jun 2008 - 07:30:41 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