as.numeric with comma decimal separators?

前端 未结 7 1689
野性不改
野性不改 2020-11-27 04:32

I have a large vector of strings of the form:

Input = c(\"1,223\", \"12,232\", \"23,0\")

etc. That\'s to say, decimals separated by commas,

7条回答
  •  -上瘾入骨i
    2020-11-27 05:22

    The readr package has a function to parse numbers from strings. You can set many options via the locale argument.

    For comma as decimal separator you can write:

    readr::parse_number(Input, locale = readr::locale(decimal_mark = ","))
    

提交回复
热议问题