validComputations: Only compute means or sums for cases with enough nonmissings

Description Usage Arguments Value Author(s) See Also Examples

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

1
2
3
4
5
6
7
8
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.

Author(s)

Gjalt-Jorn Peters

Maintainer: Gjalt-Jorn Peters <gjalt-jorn@userfriendlyscience.com>

See Also

rowMeans, rowSums

Examples

1
2
3
4
5
validMeans(mtcars$cyl, mtcars$disp);
validSums(mtcars$cyl, mtcars$disp, requiredValidValues = .8);

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

userfriendlyscience documentation built on May 2, 2019, 1:09 p.m.