将百万/十亿个缩写更改为实际数字?IE.5.12M->5,120,000 [英] Changing Million/Billion abbreviations into actual numbers? ie. 5.12M -> 5,120,000
本文介绍了将百万/十亿个缩写更改为实际数字?IE.5.12M->5,120,000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题所示,我正在寻找一种将缩写的字符"文本转换为数字数据的方法.例如,我想在我的数据框中进行以下更改:
As the title suggests I'm looking for a way to transform short hand abbreviated 'character' text to numerical data. For example I'd like to make these changes within my dataframe:
84.06M -> 84,060,000
30.12B -> 30,120,000,000
9.78B -> 9,780,000,000
251.29M -> 251,29,000
以下是我正在使用的某些数据框的示例:
Here's an example of some of the dataframe I'm working with:
Index Market Cap Income Sales Book/sh
ZX - 84.06M -1.50M 359.50M 7.42
ZTS S&P 500 30.13B 878.00M 5.02B 3.49
ZTR - - - - -
ZTO - 9.78B 288.30M 1.47B 4.28
ZPIN - 1.02B 27.40M 285.20M 4.27
ZOES - 251.29M -0.20M 294.10M 6.79
ZNH - 10.92B 757.40M 17.26B 33.23
ZF - - - - -
ZEN - 2.78B -106.70M 363.60M 3.09
ZBK - 6.06B - 2.46B 34.65
ZBH S&P 500 22.76B 712.00M 7.78B 50.94
有人有建议吗?我在想在基本R中使用gsub ...
Does anyone have some suggestions? I was thinking gsub in base r...
推荐答案
您可以尝试
num <- c("1.23M", "15.69B", "123.999M")
num <- gsub('B', 'e9', num)
num <- gsub('M', 'e6', num)
format(as.numeric(num), scientific = FALSE, big.mark = ",")
"84,060,000" "30,120,000,000" "251,290,000"
这篇关于将百万/十亿个缩写更改为实际数字?IE.5.12M->5,120,000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文