![]() |
VOOZH | about |
In this article, we are going to see the separation of numbers using a comma in R Programming Language. A comma separator in number will give clarity of a number, and we can count easily when a number is separated by a comma.
It can be done with these ways:
Method 1: Using prettyNum()
This function is used to separate the number.
Syntax: prettyNum(input_number, big.mark = ",", scientific = FALSE)
Parameters:
- input_number - input number
- big mark- it is an separator such that the number should be separated by the given delimiter.
- scientific parameter - It is set to FALSE.
Return: Number separated by comma
Example 1: R program to separate the number with a comma.
Output:
'70,589,999,999'
Example 2: R program to separate the number with a comma with scientific values
Output:
'45,000,000,000,000,000,000' '4.5e+19'
Note: we will not get the comma-separated number when scientific is set to FALSE
Method 2: Using the format()
Used to format the number with a separator
Syntax: format(input_number, big.mark = ",", scientific = FALSE)
Parameters:
- input_number - input number
- big mark- it is an separator such that the number should be separated by the given delimiter.
- scientific parameter - It is set to FALSE.
Return: Number separated by comma.
Example 1: R program to separate the number with comma
Output:
'70,589,999,999'
Example 2: R program to separate the number with a comma with scientific values
Output:
'720,589,999,999' '7.2059e+11'