0

I came across this problem: I have a data frame that I am trying to separate in two column.

    [1] 
[1] 120.3,1860
[2] 130.6,1861

I tried to separate them with the following line of code:

df.tidy <- separate(df.comma.separated, 1, "" , sep = ",", remove = FALSE, convert = TRUE)

Give me the following output:

    [1]         [2]
[1] 120.3,1860  1860
[2] 130.6,1861  1861

How do I get rid of the ",1860" and the ",1861" from the input value? Thank you for your help.

NelsonGon
  • 13,015
  • 7
  • 27
  • 57

1 Answers1

0

You need to specify the into= parameter of separate, i.e.

separate(df, 1, c('a', 'b'), sep = ",", remove = FALSE, convert = TRUE)

#          v1     a    b
#1 120.3,1860 120.3 1860
#2 130.6,1861 130.6 1861

Change remove = TRUE If you do not want column v1, i.e.

separate(df, 1, c('a', 'b'), sep = ",", convert = TRUE)
#      a    b
#1 120.3 1860
#2 130.6 1861
Sotos
  • 51,121
  • 6
  • 32
  • 66
  • 1
    Thank you very much! Worked like a charm. Sorry, I am new so my syntax might be off. –  Jan 24 '19 at 10:17