Back
Is there a function in R to display large numbers separated with commas?
i.e., from 1000000 to 1,000,000.
You can use the format or prettyNum function to represent numbers with commas as follows:
format(13579.246,big.mark=",",scientific=FALSE)[1] "13,579.25"prettyNum(13579.246,big.mark=",",scientific=FALSE)[1] "13,579.25"
format(13579.246,big.mark=",",scientific=FALSE)
[1] "13,579.25"
prettyNum(13579.246,big.mark=",",scientific=FALSE)
To avoid the padding of printed strings with blank, use the following:
format(c(123,1234),big.mark=",", ) #with padding[1] " 123" "1,234"> format(c(123,1234),big.mark=",", trim=TRUE) #without padding[1] "123" "1,234"
format(c(123,1234),big.mark=",", ) #with padding
[1] " 123" "1,234"
> format(c(123,1234),big.mark=",", trim=TRUE) #without padding
[1] "123" "1,234"
Similarly in prettyNum
prettyNum(c(123,1234),big.mark=",", preserve.width="none")[1] "123" "1,234"
prettyNum(c(123,1234),big.mark=",", preserve.width="none")
30.9k questions
32.9k answers
500 comments
665 users