0

I would like to split a double-line character column into two columns in R.

For instance, turn the character column below:

"0311I250 61I272 62E669                                                                                                                                                            03 I250 E669 I272"

into two columns

## "0311I250 61I272 62E669" "03 I250 E669 I272".

Anyone can help?

Thanks a lot.

hwnd
  • 69,796
  • 4
  • 95
  • 132
Emily
  • 3
  • 1
  • Welcome to StackOverflow. Can you please provide some more information on the logic of this split. For example, is the split on the third space, or after a fixed number of characters? – Andrie Dec 09 '16 at 16:52
  • `strsplit(your_string, '\\s{2,}')[[1]]` – alistaire Dec 09 '16 at 16:57
  • 1
    I'd go for `data.table::tstrsplit(x, "\\n")` but there are a lot of other options in the link too. – Frank Dec 09 '16 at 17:18

1 Answers1

2

strsplit at blank with two digits after it.

unlist(strsplit(string,'(\\s)(?=\\d{2}\\s+)',perl=T))
[1] "0311I250 61I272 62E669" "03 I250 E669 I272" 
Shenglin Chen
  • 4,504
  • 11
  • 11