Learn R Programming

dataprep (version 0.1.8)

percdata: 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)

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.

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.

Author

Chun-Sheng Liang <[email protected]>

Details

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

References

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

Examples

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

Run the code above in your browser using DataLab