Display Large Numbers Separated with Comma in R (2 Examples)


In this tutorial you’ll learn how to separate numbers with a comma in the R programming language.

The article consists of this content:

It’s time to dive into the examples!


Creation of Example Data

Have a look at the following example data:

x <- 10000000                                     # Example number
x                                                 # Print number to RStudio console
# 1e+07

As you can see based on the previous output of the RStudio console, our example data is a simple data object consisting of one large number.


Example 1: Comma-Separate Numbers with prettyNum Function

This Example shows how to format numeric values to have a comma-separator (i.e. the European way instead of the American way) using the prettyNum command in R.

prettyNum(x, big.mark = ",", scientific = FALSE)  # Apply prettyNum function
# "10,000,000"

Have a look at the previous output of the RStudio console. As you can see, our example number is displayed with a comma-separator


Example 2: Comma-Separate Numbers with format Function

In this Example, I’ll illustrate how to display a large number with commas based on the format function.

format(x, big.mark = ",", scientific = FALSE)     # Apply format function
# "10,000,000"

The output is the same as in Example 1!


Video & Further Resources

Do you need more explanations on the content of this tutorial? Then you could watch the following video of the Statistics Globe YouTube channel. In the video, I’m showing the R code of this article:



Furthermore, you might read some of the other tutorials of statisticsglobe.com. I have published numerous tutorials already.


At this point you should have learned how to format numbers to have a comma-separator in the R programming language. In case you have any additional questions, let me know in the comments section.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.