我有一个这样的变量:
| 勇气 |
|---|
| 3.554,34 |
| 56,34 |
但它的类是“字符”,当我编码时:
gastosbolsonaro <- gastosbolsonaro %>% mutate(VALOR = as.numeric(VALOR))
Run Code Online (Sandbox Code Playgroud)
发生这样的事:
Problem while computing `VALOR = as.numeric(as.character(VALOR))`.
i NAs introduced by coercion
Run Code Online (Sandbox Code Playgroud)
所有值都变为 NA。
我想将超值货币更改为数字类别
您可以使用parse_numberreadr 包
library(readr)
x <- c("3.554,34", "56,34")
parse_number(x, locale = locale(decimal_mark = ",", grouping_mark = "."))
[1] 3554.34 56.34
Run Code Online (Sandbox Code Playgroud)