0

I have some data which I have already split them by colons. I want to split all the contents of each column by colon.

Here is an example of my data:

                      V8                        V9                      V10
1 0/0:0,108,255:36:0:0:99  0/0:0,255,255:103:0:0:99 0/0:0,226,255:107:3:0:99
2 1/1:255,69,0:23:23:0:65  1/1:255,159,0:63:62:0:99 0/1:255,0,255:58:25:4:99

and I want them to look like:

                      V8                        V9                      V10
1 0/0 0,108,255 36 0 0 99  0/0 0,255,255 103 0 0 99 0/0 0,226,255 107 3 0 99
2 1/1 255,69,0 23 23 0 65  1/1 255,159,0 63 62 0 99 0/1 255,0,255 58 25 4 99
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Assuming your data.frame is called SODF, use gsub. lapply will let you apply the function to all the columns in your data.frame (since a data.frame is a special kind of list in R):

> data.frame(lapply(SODF, function(x) gsub(":", " ", x)))
                       V8                       V9                      V10
1 0/0 0,108,255 36 0 0 99 0/0 0,255,255 103 0 0 99 0/0 0,226,255 107 3 0 99
2 1/1 255,69,0 23 23 0 65 1/1 255,159,0 63 62 0 99 0/1 255,0,255 58 25 4 99
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485