percdata: Calculate top and bottom percentiles of selected variables

View source: R/percdata.R

percdataR Documentation

Calculate top and bottom percentiles of selected variables

Description

Computes percentiles (quantiles) for selected numeric columns. By default, six bottom percentiles (0th to 0.5th) and six top percentiles (99.5th to 100th) are calculated. The function supports grouping.

Usage

percdata(data, cols = NULL, group = NULL, diff = 0.1,
        part = "both", na.rm = TRUE, verbose = FALSE)

Arguments

data

A data frame, matrix, or numeric vector. If a vector, a data frame is created internally.

cols

Column indices or names of numeric variables. If NULL, all numeric columns are used.

group

Optional grouping column index or name. If provided, percentiles are computed separately for each group.

diff

Common difference between quantile probabilities. Default is 0.1.

part

Which parts to return: "both" (default), "bottom", or "top". For backward compatibility, part also accepts the integer codes 2 ("both"), 0 ("bottom"), and 1 ("top").

na.rm

Logical; if TRUE, NA values are removed before quantile computation.

verbose

Logical; if TRUE, prints timing message.

Details

The function uses stats::quantile() on each selected column. For grouped data, percentiles are computed within each group.

Value

A data frame with rows corresponding to percentiles and columns corresponding to variables (plus a percentile column). If grouped, an additional grouping column is present.

Author(s)

Chun-Sheng Liang <chun-shengliang@qq.com>

References

1. Example data is from https://smear.avaa.csc.fi/download. It includes particle number concentrations in SMEAR I Varrio forest.

Examples

percdata(data, cols = 27:61, group = 4)

dataprep documentation built on Oct. 1, 2026, 5:07 p.m.