The “trunc” Function in R
Package: Base R (No specific package, it’s a built-in function)
Purpose: To truncate numeric values towards zero, effectively removing the decimal part.
General Class: Mathematical Computation
Required Argument(s):
x: A numeric vector or value to be truncated.
Notable Optional Arguments:
None
Example:
# Example usage
values <- c(3.14, -2.718, 5.55)
# Truncate towards zero
truncated_values <- trunc(values)
print(truncated_values)In this example, trunc is a built-in function in base R, and it is used to truncate numeric values towards zero, effectively removing the decimal part. The x argument is the required numeric vector or value to be truncated. There are no notable optional arguments for this function. The result is a numeric vector or value that has been truncated towards zero.