Jason Ching Yuk Jason Ching Yuk - 3 months ago 10
R Question

Splitting Columns that contain decimal point values in R

I facing difficulties splitting columns in R. For instance

Col1.Col2.Col3
12.3,10,11
11.3,11,50
85,89.3,90
and over 100x records


I did

tidyr::separate(df, Col1.Col2.Col3,
c("Col1", "Col2", "Col3" ))


And i get

Col1 Col2 Col3
12 3 10
11 3 11
85 89 3
and over 100x records


I realised that the decimal value is moved to the next column and the values of Col3 were left out. How can i fix this or is there a better way of splitting the columns?

Answer

tidyr::separate has a sep argument that controls where the splits occur. Use sep = ",".

Comments