0

i imported a df with p - values, which are in character. When converting these into numeric with as.numeric, I only get NAs.

df = c("8,333333e-06")

how can I convert these into numeric?

Phil
  • 7,287
  • 3
  • 36
  • 66
MA_1760
  • 31
  • 5
  • Does this answer your question? [as.numeric with comma decimal separators?](https://stackoverflow.com/questions/15236440/as-numeric-with-comma-decimal-separators) –  May 31 '22 at 12:57
  • 1
    Keep in mind that fixing afterwards can often be prevented by reading in your data the right way. Perhaps you can avoid this by reading in your data specifying the decimal speperator. Then you probably would not have had a string but the correct numbers without a need to fix them afterwards. – Merijn van Tilborg May 31 '22 at 13:05

1 Answers1

0

Change , to . with sub and then use as.numeric.

as.numeric(sub(",", ".", "8,333333e-06"))
#[1] 8.333333e-06

Maybe this can already be solved when reading in the data by defining the dec sign. In read.table this would be in his case done by dec = ",".

GKi
  • 37,245
  • 2
  • 26
  • 48