Learn R Programming

SlotLim (version 0.0.2)

percentile: percentile

Description

Calculates specified percentiles from length-frequency data.

Usage

percentile(
  LF = NULL,
  probs = c(0.025, 0.975),
  na.rm = TRUE,
  sort_probs = TRUE,
  unique_probs = TRUE
)

Value

A named list (length = length of probs) where each element corresponds to the requested percentile. Names are formatted as L_x, where x is the percentile value in percent (e.g., L_2.5, L_97.5).

Arguments

LF

Numeric vector of length-frequency data (e.g., data$length).

probs

Numeric vector of probabilities in \([0,1]\) indicating which percentiles to calculate. Default is c(0.025, 0.975) as per SlotLim.

na.rm

Logical; if TRUE (default), NAs are removed before computing percentiles. If FALSE, NA values may propagate to the result.

sort_probs

Logical; if TRUE (default), probs are sorted ascending (labels follow the returned order). If FALSE, percentiles are returned in the input order.

unique_probs

Logical; if TRUE (default), duplicate probs are deduplicated (first occurrence kept for labeling).

Details

Uses stats::quantile(..., type = 7), the R default. Labels drop trailing zeros (e.g., L_5 not L_5.0).

Examples

Run this code
length_data <- c(10, 9, 7, 10, 11, 13, NA, 11, 6, 20)
percentile(length_data)  # default 2.5th and 97.5th
percentile(length_data, probs = c(0.05, 0.95)) # 5th and 95th percentiles

Run the code above in your browser using DataLab