Calculates the percentile ranking of a value within a vector of values. This function was moved from artbenchmark to artutils to respect the package dependency hierarchy.
Usage
calc_percentile(val, vec, trim = c(0, 1))Details
Percentile calculation uses the rank-based method: - 1 = value is below the minimum (outside range) - 0.5 = value equals the minimum - 50 = value is at the median - 99.5 = value equals the maximum - 100 = value is above the maximum (outside range)
The trim parameter allows you to exclude extreme values from the comparison vector before calculating the percentile.
Note
This function was previously exported by the artbenchmark package. It has been moved to artutils to maintain proper dependency hierarchy: artcore <- artutils <- artbenchmark.
See also
Other utilities:
utils
Examples
# Basic usage
calc_percentile(25, 1:100) # Returns 24.5
#> [1] 24.5
calc_percentile(75, 1:100) # Returns 74.5
#> [1] 74.5
# Edge cases
calc_percentile(1, 1:100) # Returns 0.5 (at minimum)
#> [1] 0.5
calc_percentile(100, 1:100) # Returns 99.5 (at maximum)
#> [1] 99.5
calc_percentile(0, 1:100) # Returns 1 (below minimum)
#> [1] 1
calc_percentile(150, 1:100) # Returns 100 (above maximum)
#> [1] 100
