meanif: Mean

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Returns the mean of a vector, matrix, or data.frame if it has nomiss proportion of valid cases

Usage

1
meanif(set, nomiss = 0.8, tr = 0)

Arguments

set

A vector, matrix, or data.frame

nomiss

A numeric vector specifying the proporiton of valid cases in set (i.e. data that must not be NA) for the mean to be returned

tr

A numeric specifying the amount of trimming if desired

Details

The built in r function mean includes an na.rm argument that allows the computation of a mean excluding missing cases. However, sometimes one wants to calculate the mean of an object so long as some proportion of those cases are present. The nomiss option of this function allows this capability. If fewer than the nomiss proportion of the cases are invalid (i.e. misssing) the function will return NA. Otherwise, it will return the mean of the valid cases.

Value

Returns the mean.

Author(s)

Ryne A Sherman

See Also

mean

Examples

1
2
3
4
5
6
data(RSPdata)
RSPdata$sEXT #no missing values 
meanif(RSPdata$sEXT,nomiss=1)
RSPdata$sEXT[100] <- NA #now we make one value missing
meanif(RSPdata$sEXT,nomiss=1) #returns NA
meanif(RSPdata$sEXT,nomiss=.8) #returns value

multicon documentation built on May 2, 2019, 3:18 a.m.