Splits the data into subsets (according to the levels of a factor) and computes a weighted quantile for each

agg.wtd.quantile(x, by, weights = NULL, prob = 0.5, na.rm = FALSE)

Arguments

x

numeric vector or data frame of numeric vectors

by

factor used to split the data

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

prob

a value between 0 and 1. Default is 0.5 (median)

na.rm

logical, indicating whether NA values should be silently removed before the computation proceeds. Default is FALSE.

Value

a data frame

Author

Nicolas Robette

See also

Examples

data(Movies)
agg.wtd.quantile(Movies[,c("Critics", "BoxOffice")], by = Movies$Country)
#>         Critics BoxOffice
#> Europe 3.000000  108121.5
#> France 3.000000   57140.0
#> Other  3.208333   55643.0
#> USA    2.666667  328559.0