Round Function in R:

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:

round(x, digits = 0)
  • 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)
output:
[1] 125.24

 

# round off in R with 0 decimal places - with R round function

round(125.2395, digits=0)
output:
[1] 125

 

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)
output:
[1] 1.23  2.34  4.56  5.67 12.35 14.57

 

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)
output:

digits argument is 4 which means the total number of digits will be 4

[1] 125.2

other way of rounding off numbers in r are Truncate, floor and ceiling.

round function in r                                                                                                                round function in R