colMeans_if: Column Means Conditional on Frequency of Observed Values

Description Usage Arguments Details Value See Also Examples

View source: R/quest_functions.R

Description

colMeans_if calculates the mean of every column in a numeric or logical matrix conditional on the frequency of observed data. If the frequency of observed values in that column is less than (or equal to) that specified by ov.min, then NA is returned for that row.

Usage

1
colMeans_if(x, ov.min = 1, prop = TRUE, inclusive = TRUE)

Arguments

x

numeric or logical matrix. If not a matrix, it will be coerced to one.

ov.min

minimum frequency of observed values required per column. If prop = TRUE, then this is a decimal between 0 and 1. If prop = FALSE, then this is a integer between 0 and nrow(x).

prop

logical vector of length 1 specifying whether ov.min should refer to the proportion of observed values (TRUE) or the count of observed values (FALSE).

inclusive

logical vector of length 1 specifying whether the mean should be calculated if the frequency of observed values in a column is exactly equal to ov.min.

Details

Conceptually this function does: apply(X = x, MARGIN = 2, FUN = mean_if, ov.min = ov.min, prop = prop, inclusive = inclusive). But for computational efficiency purposes it does not because then the missing values conditioning would not be vectorized. Instead, it uses colMeans and then inserts NAs for columns that have too few observed values.

Value

numeric vector of length = ncol(x) with names = colnames(x) providing the mean of each column or NA depending on the frequency of observed values.

See Also

colSums_if rowMeans_if rowSums_if colMeans

Examples

1
2
colMeans_if(airquality)
colMeans_if(x = airquality, ov.min = 150, prop = FALSE)

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to colMeans_if in quest...