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:
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Furthermore, you might read some of the other tutorials of statisticsglobe.com. I have published numerous tutorials already.
- Disable Scientific Notation in R
- Change Formatting of Numbers of ggplot2 Plot Axis
- Format Number of Decimal Places in R
- The sprintf R Function
- The R Programming Language
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.
Statistics Globe Newsletter