mean_if: Mean Conditional on Minimum Frequency of Observed Values

Description Usage Arguments Value See Also Examples

View source: R/quest_functions.R

Description

mean_if calculates the mean of a numeric or logical vector conditional on a specified minimum frequency of observed values. If the frequency of observed values is less than (or equal to) ov.min, then NA is returned rather than the mean.

Usage

1
mean_if(x, trim = 0, ov.min = 1, prop = TRUE, inclusive = TRUE)

Arguments

x

numeric or logical vector.

trim

numeric vector of length 1 specifying the proportion of values from each end of x to trim. Trimmed values are recoded to their endpoint for calculation of the mean. See mean.default.

ov.min

minimum frequency of observed values required. If prop = TRUE, then this is a decimal between 0 and 1. If prop = FALSE, then this is a integer between 0 and length(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 is exactly equal to ov.min.

Value

numeric vector of length 1 providing the mean of x or NA conditional on if the frequency of observed data is greater than (or equal to) ov.min.

See Also

mean.default sum_if make.fun_if

Examples

1
2
3
4
5
6
7
mean_if(x = airquality[[1]], ov.min = .75) # proportion of observed values
mean_if(x = airquality[[1]], ov.min = 116,
   prop = FALSE) # count of observe values
mean_if(x = airquality[[1]], ov.min = 116, prop = FALSE,
   inclusive = FALSE) # not include ov.min value itself
mean_if(x = c(TRUE, NA, FALSE, NA),
   ov.min = .50) # works with logical vectors as well as numeric

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

Related to mean_if in quest...