Split string on first two colons

Posted by Mark Miller on Stack Overflow See other posts from Stack Overflow or by Mark Miller
Published on 2013-11-03T03:28:49Z Indexed on 2013/11/03 3:53 UTC
Read the original article Hit count: 129

Filed under:
|
|

I would like to split a column of strings on the first two colons, but not on any subsequent colons:

my.data <- read.table(text='

my.string    some.data
12:34:56:78    -100
87:65:43:21    -200
a4:b6:c8888    -300
11:bb:ccccc    -400
uu:vv:ww:xx    -500', header = TRUE)

desired.result <- read.table(text='

my.string1  my.string2  my.string3  some.data
12          34          56:78         -100
87          65          43:21         -200
a4          b6          c8888         -300
11          bb          ccccc         -400
uu          vv          ww:xx         -500', header = TRUE)

I have searched extensively and the following question is the closest to my current dilemma:

Split on first comma in string

Thank you for any suggestions. I prefer to use base R.

© Stack Overflow or respective owner

Related posts about regex

Related posts about string