weighted_pct: Weighted proportion table

View source: R/weighted_pct.R

weighted_pctR Documentation

Weighted proportion table

Description

This is a fast, dependency-free weighted proportion table for 1D variables.

Usage

weighted_pct(x, weights)

Arguments

x

A vector of any type

weights

A numeric vector of weights, equal in length to x

Value

A named vector with weighted proportions.

Examples

# Setup examle data
x <- c(rep(1, 5), rep(2, 5))
weights <- c(rep(1, 5), rep(2, 5))

# Unweighted proportions: 0.5 / 0.5
prop.table(table(x))
# Weighted proportions: 0.33 / 0.66
weighted_pct(x, weights)

aaronrudkin/autumn documentation built on Feb. 5, 2024, 6:08 p.m.