将缩写 "numbers" 转换为 R 中的数字
Converting abbreviated "numbers" into numbers in R
我在 R 中有一个数据框,其中 ,000
和 ,000,000
等货币值分别输入为 25K
和 2M
。数据框很大,所以有什么办法可以,例如,将所有 2M
更改为 2000000
?
在字母上尝试 gsub():
df$variableName <- gsub("M", "000000", df$variableName)
df$variableName <- gsub("K", "000", df$variableName)
等等...
也许可以在完成后转换 class class(df$variable) <- "numeric"
。
我在 R 中有一个数据框,其中 ,000
和 ,000,000
等货币值分别输入为 25K
和 2M
。数据框很大,所以有什么办法可以,例如,将所有 2M
更改为 2000000
?
在字母上尝试 gsub():
df$variableName <- gsub("M", "000000", df$variableName)
df$variableName <- gsub("K", "000", df$variableName)
等等...
也许可以在完成后转换 class class(df$variable) <- "numeric"
。