0

I would like to split a column of names, into two columns by the first white space. In this example, we have two white spaces, but could be more.

a <- "Lucero del Alba"

The expected outcome:

> c
[1] "Lucero"   "del Alba"

Approach 1, wrong because is deleating "Lucero del" :

> strsplit("Lucero del Alba", "^.+ ")
[[1]]
[1] ""     "Alba"

Approach 2, good, but how do I get the rest?

> strsplit("Lucero del Alba", " .+$")
[[1]]
[1] "Lucero"
Mario GS
  • 859
  • 8
  • 22
  • 1
    Possible duplicate of [Splitting a string on the first space](http://stackoverflow.com/questions/8299978/splitting-a-string-on-the-first-space) but the answers [here](http://stackoverflow.com/questions/10309122/split-on-first-comma-in-string) are better – rawr Aug 26 '16 at 22:32
  • Yes, I just found that, it is duplicated. – Mario GS Aug 26 '16 at 22:41
  • If you can control the number of splits, set it for 1 and just use [ ]+ –  Aug 27 '16 at 01:30

0 Answers0