Rounding Functions

DESCRIPTION:
Returns an object like the input but with the numbers rounded or retaining only a specified number of significant digits.

USAGE:
round(x, digits=0)
signif(x, digits=6)

REQUIRED ARGUMENTS:
x:
numeric or complex object. Missing values (NAs) are accepted.

OPTIONAL ARGUMENTS:
digits:
number of decimal digits after the decimal point, in the case of round, and the total number of digits, in the case of signif. For rounding, digits can be negative, for rounding large numbers to the nearest 10, 100, etc.

VALUE:
object like x with data rounded to the specified number of places (round), or with the specified number of significant digits retained (signif).

CLASSES:
This function will be used as the default method for classes that do not inherit a specifc method for the function or for the Math group of functions. The result will retain the class and the attributes. If this behavior is not appropriate, the designer of the class should provide a method for the function or for the Math group.

DETAILS:
These functions are in the Math group of generic functions - see Methods.

When rounding off a 5, the two common conventions are to: 1) go to the higher number, or 2) go to the even digit. The round function obeys convention 2, so round(2.5) is 2 and round(3.5) is 4. The rounding mechanism for signif is machine dependent, but most machines will use the "round to even" rule.


SEE ALSO:
ceiling .

EXAMPLES:
round(mydata, dig=2)    #round to 2 decimals
round(mydata, -1)       #round to nearest 10

x <- c(123456, .123456, .000123456)

round(x, 3) # produces [1] 123456.000 0.123 0.000

signif(x, 3) # produces [1] 1.23e+05 1.23e-01 1.23e-04

round(c(-1.9, -1.1, 1.1, 1.9)) # produces [1] -2 -1 1 2