Skip to contents

prop() computes the proportion of specified values in a vector.

Usage

prop(x, value, na_rm = TRUE)

Arguments

x

An atomic vector.

value

An atomic vector containing values for which to compute proportions.

na_rm

A logical flag indicating whether to remove NA values from x before computing proportions (default: TRUE).

Value

A numeric vector with the proportions of each value in value relative to the total number of values in x.

See also

Other statistical functions: cut_interval_mean(), remove_outliers(), std_error(), test_outlier()

Examples

prop(c("a", "b", "a", "c", "b", "a"), c("a", "b"))
#> [1] 0.5000000 0.3333333
#> [1] 0.500000 0.3333333 # Expected

prop(c(1, 2, 1, 2, 1), c(1, 2, 5))
#> [1] 0.6 0.4 0.0
#> [1] 0.6 0.4 NA # Expected

prop(c(TRUE, TRUE, TRUE, FALSE), c(TRUE, FALSE))
#> [1] 0.75 0.25
#> [1] 0.75 0.25 # Expected