The “sum” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Calculates the sum of numeric values in a vector.

  • General Class: Descriptive Statistics

  • Required Argument(s):

    • x: A numeric vector.

  • Notable Optional Arguments:

    • na.rm: A logical value indicating whether NA values should be stripped before the computation proceeds. The default is FALSE.

  • Example:

  • # Example vector
    data <- c(2, 4, 6, 8, 10, NA)

    # Calculate sum excluding NA values
    result <- sum(data, na.rm = TRUE)
    print(result)

  • In this example, the sum function calculates the sum of the numeric vector data. The na.rm argument is set to TRUE to exclude NA values from the calculation. The result is then printed to the console.

Previous
Previous

The “sd” Function in R

Next
Next

The “median” Function in R