Rounding off values in R Language – round() Function
round() function in R Language is used to round off values to a specific number of decimal value.
Syntax: round(x, digits)
Parameters:
x: Value to be round off
digits: Number of digits to which value has to be round off
Example 1: Rounding off the values
Python3
x1 < - 1.2
x2 < - 1.8
x3 < - - 1.3
x4 < - 1.7
round (x1)
round (x2)
round (x3)
round (x4)
print (x1, x2, x3, x4)
|
Output :
1
2
-1
2
Here in the above code, we have round off the values with 4 data x1, x2, x3, and x4 using the function round(), and printed the new values.
Example 2: Rounding off to certain digits
Python3
x2 < - 3.14734343243
round (x2, digits = 3 )
print (x2)
|
Output:
3.147
Here in the above code, the value of a numeric vector is round off till 3 digits.
Last Updated :
15 Apr, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...