-5

In my data.frame, I have a column of type character, where all the values look like this : 123_456 (three digits, an underscore, three digits).

I need to transform these values to a numeric, and as.numeric(my_dataframe$my_column) gives me a NA. Therefore I need to remove the underscore first, in order to do as.numeric.

How would I do that please ?

Thanks

François M.
  • 4,027
  • 11
  • 30
  • 81

1 Answers1

14

We can use sub

as.numeric(sub("_", "", my_dataframe$my_column))
akrun
  • 874,273
  • 37
  • 540
  • 662