0 votes
1 view
in R Programming by (6.5k points)

Is there a function in R to display large numbers separated with commas?

i.e., from 1000000 to 1,000,000.

1 Answer

0 votes
by (25.3k points)

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"

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"

Similarly in prettyNum

prettyNum(c(123,1234),big.mark=",", preserve.width="none")

[1] "123"   "1,234"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...