Learn R Programming

multicon (version 1.6)

meanif: Mean

Description

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

Usage

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

Value

Returns the mean.

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.

See Also

mean

Examples

Run this code
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

Run the code above in your browser using DataLab