Create, or test for, objects of type projectable_col_freq.

col_freq(n = double(), N = double(), p = NULL, weight = 1, summarised = FALSE)

is_col_freq(x)

Arguments

n

A numeric vector of pre-calculated frequencies or a vector which sums to a frequency

N

A numeric vector of pre-calculated base frequencies or a vector which sums to a base frequency

p

A numeric vector of proportions, defaults to the quotient of n and N

weight

A numeric vector of weights for calculating weighted frequencies.

summarised

A logical flagging whether or not n and N are being supplied in summarised form or not. If FALSE, n and N will be summed across to calculate frequencies.

x

An object to test

Value

An S3 vector of class projectable_col_freq

Examples


# Calculate and store the frequency of manual cars in `mtcars` data set
col_freq(mtcars$vs %in% 1, mtcars$vs %in% 0:1)
#> <col_freq[1]>
#> [1] 0.44

# Pre-calculate a range of frequencies and store them
dummy_data <- lapply(1:5, function(x) runif(100))
little_n <- vapply(dummy_data, function(x) sum(x >= 0.5), integer(1))
big_n <- vapply(dummy_data, length, integer(1))
col_freq(little_n, big_n, summarised = TRUE)
#> <col_freq[5]>
#> [1] 0.52 0.51 0.45 0.54 0.39