How to add a comma to a set of numbers
x <- c(1011, 10121, 100000)
prettyNum(x, big.mark = ',')
## [1] "1,011" "10,121" "1e+05"
Removing scientific notation
prettyNum(x, big.mark = ',',scientific=FALSE)
## [1] "1,011" "10,121" "100,000"
Adding comma to a dataframe
df <- data.frame(a = c('a', 'b', 'c'), current_number = x)
library(dplyr)
df %>% mutate(new_number = prettyNum(x, big.mark = ',',scientific=FALSE))
## a current_number new_number
## 1 a 1011 1,011
## 2 b 10121 10,121
## 3 c 100000 100,000
Add a dollar sign to the number, with comma, and round the cents
library(scales)
y <- c(1211.122, 1234.1212313212)
dollar(y)
## [1] "$1,211.12" "$1,234.12"
Add dollar sign to a data frame column
df %>% mutate(current_number = scales::dollar(current_number))
## a current_number
## 1 a $1,011
## 2 b $10,121
## 3 c $100,000