Is there an easier way to format currencies in R. The following code, generates a small table -
library(dplyr)
set.seed(1)
data = sample(5000:1500000,10, replace = F)
data = tibble(data)
data %>% mutate(currency = scales::dollar(data))
data currency
<int> <chr>
1 457736 $457,736
2 129412 $129,412
3 1490098 $1,490,098
4 861017 $861,017
5 30172 $30,172
6 1348337 $1,348,337
7 1446261 $1,446,261
8 645774 $645,774
9 543190 $543,190
10 1323948 $1,323,948
I will like to generate a new column that formats the data such that -
$457,736 will be $457K
$1,490,098 will be $1.5M
$30,172 will be $30K