validComputations: Only compute means or sums for cases with enough nonmissings
Description
These functions have been written as equivalents of SPSS' MEAN.x and SUM.x functions, which only compute means and sums if enough cases have valid values.
Either a dataframe or vectors for which to compute the mean or sum.
requiredValidValues
How many values must be valid (i.e. nonmissing) to compute the mean or sum. If a number lower than 1 is provided, it is interpreted as proportion, and the number of variables is computed. For example, if requiredValidValues=.8, 80% of the variables must have valid values. If 'all' is specified, all values must be valid (in which case the functions are equal to rowMeans and rowSums).
returnIfInvalid
Wat to return for cases that don't have enough valid values.
silent
Whether to show the number of cases that have to be valid if requiredValidValues is a proportion.
Value
A numeric vector with the resulting means or sums.
# NOT RUN {validMeans(mtcars$cyl, mtcars$disp);
validSums(mtcars$cyl, mtcars$disp, requiredValidValues = .8);
### Or specifying a dataframevalidSums(mtcars);
# }