# sum_if: Sum Conditional on Minimum Frequency of Observed Values In quest: Prepare Questionnaire Data for Analysis

## Description

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

## Usage

 `1` ```sum_if(x, impute = TRUE, ov.min = 1, prop = TRUE, inclusive = TRUE) ```

## Arguments

 `x` numeric or logical vector. `impute` logical vector of length 1 specifying if missing values should be imputed with the mean of observed values of `x`. If TRUE (default), this will make sums over the same vectors with different amounts of missing data comparable. `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 sum should be calculated (rather than NA) if the frequency of observed values is exactly equal to `ov.min`.

## Value

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

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