Round function in R, rounds off the values in its first argument to the specified number of decimal places.
Syntax of Round() function in R:
- x – numeric value or vector to be rounded off
- digits – number of digits to which the value has to be rounded off.
Example of Round function in R:
# round off in R with 2 decimal places - with R round function round(125.2395,2)
# round off in R with 0 decimal places - with R round function round(125.2395, digits=0)
Example of Round function in R for vector:
# round function in R with 2 decimal places for a vector round(c(1.234,2.342,4.562,5.671,12.345,14.567),digits = 2)
Signif() function in R for rounding off:
Signif() function is similar to round function, but digits argument in signif() function denotes the total digits, not the digits after decimal.
# signif function in R with total of 4 digits signif(125.2395, digits=4)
digits argument is 4 which means the total number of digits will be 4