The “round” Function in R
Package: Base R (No specific package, it’s a built-in function)
Purpose: To round numeric values to the nearest integer or a specified number of decimal places.
General Class: Mathematical Computation
Required Argument(s):
x: A numeric vector or value to be rounded.
Notable Optional Arguments:
digits: An integer specifying the number of decimal places to round to. The default is 0.
Example:
# Example usage
values <- c(3.14, 2.718, 5.55)
# Round to the nearest integer
rounded_integers <- round(values)
# Round to two decimal places
rounded_decimals <- round(values, digits = 2)
print(rounded_integers)
print(rounded_decimals)In this example, round is a built-in function in base R, and it is used to round numeric values. The x argument is the required numeric vector or value to be rounded. The digits argument is optional and specifies the number of decimal places to round to (default is 0). The result is a numeric vector or value that has been rounded according to the specified precision.