Learn R Programming

userfriendlyscience (version 0.7.2)

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.

Usage

validMeans(...,
           requiredValidValues = 0,
           returnIfInvalid = NA,
           silent = FALSE)
validSums(...,
          requiredValidValues = 0,
          returnIfInvalid = NA,
          silent = FALSE)

Arguments

...

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.

See Also

rowMeans, rowSums

Examples

Run this code
# NOT RUN {
validMeans(mtcars$cyl, mtcars$disp);
validSums(mtcars$cyl, mtcars$disp, requiredValidValues = .8);

### Or specifying a dataframe
validSums(mtcars);
# }

Run the code above in your browser using DataLab