+2 votes
in Programming Languages by (157k points)
I want to round decimal numbers to 2 and 3 decimal places, but the round() function returns the nearest integer. Is there any other function for it?

1 Answer

+3 votes
by (33.6k points)
selected by
 
Best answer

The round() function in R has a parameter "digits" to specify the number of decimal places. The default value of the parameter is 0, and hence it returns the nearest integer. You can set this parameter according to your requirement.

Here is an example to show how to use this parameter:

> round(12.5643435, digits = 2)

[1] 12.56

> round(12.5643435, digits = 3)

[1] 12.564


...