The “format” Function in R

  • Package: Base R (No specific package, it’s a built-in function)

  • Purpose: To format numeric or date-time objects for pretty printing.

  • General Class: Data Manipulation

  • Required Argument(s):

    • x: A numeric or date-time object to be formatted.

  • Notable Optional Arguments:

    • ...: Additional arguments depending on the class of x and the desired format.

  • Example:

  • # Example usage
    numeric_value <- 12345.6789

    # Format the numeric value with commas and a specified number of digits
    formatted_numeric <- format(numeric_value, big.mark = ",", digits = 2)

    print(formatted_numeric)

  • In this example, format is a built-in function in base R, and it is used to format a numeric value (numeric_value) by adding commas as thousands separators and rounding to a specified number of significant digits. The x argument is required, and additional optional arguments (big.mark and digits) are used for formatting. The result is a formatted character string.

Previous
Previous

The “nchar” Function in R

Next
Next

The “sprintf” Function in R