Try this:
> library(gsubfn)
> strapply(x, "[0-9]+| +[^ ]+ *")[[1]]
[1] "2" " Value " "34" " a-c " "45" " t"
which keeps the spaces around the non-numeric entries as in
your example; however, if keeping the spaces is not important
then its even easier:
> strsplit(x, " ")[[1]]
[1
Dear list,
I am trying to split a string using regexp:
x <- "2 Value 34 a-c 45 t"
strsplit(x, "[0-9]")
[[1]]
[1] "" " Value " "" " a-c " "" " t"
But I don't want to lose the digits (pattern), the result
should be:
[[1]]
[1] "2" " Value " "34" " a-c " "45" " t"
Thanks for any tipp
Pat
2 matches
Mail list logo