The “which.max” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Identifies the index of the first maximum value in a numeric vector.

  • General Class: Indexing

  • Required Argument(s):

    • x: A numeric vector.

  • Notable Optional Arguments:

    • None

  • Example:

  • # Example data for using the which.max function
    numeric_vector <- c(3, 8, 2, 10, 5)

    # Use which.max to find the index of the first maximum value
    max_index <- which.max(numeric_vector)

    # Display the result
    print(max_index)

  • In this example, the which.max function is used to find the index of the first maximum value in a numeric vector (numeric_vector). The resulting index (max_index) corresponds to the position of the first occurrence of the maximum value in the vector. The which.max function is commonly used when you need to locate the index of the maximum value in a numeric vector.

Previous
Previous

The “which.min” Function in R

Next
Next

The “all” Function in R