This function is similar to the SPSS
MEAN.n function and computes
row means from a
matrix if at least
values of a row are valid (and not
mean_n(dat, n, digits = 2)
A data frame with at least two columns, where row means are applied.
May either be
If a row's sum of valid values is less than
Numeric value indicating the number of decimal places to be used for rounding mean value. Negative values are allowed (see 'Details').
A vector with row mean values of
df for those rows with at least
valid values. Else,
NA is returned.
Rounding to a negative number of
digits means rounding to a power of
ten, so for example mean_n(df, 3, digits = -2) rounds to the
n, must be a numeric value from
a row in
dat has at least
n non-missing values, the
row mean is returned. If
n is a non-integer value from 0 to 1,
n is considered to indicate the proportion of necessary non-missing
values per row. E.g., if
n = .75, a row must have at least
ncol(dat) * n
non-missing values for the row mean to be calculated. See 'Examples'.
dat <- data.frame(c1 = c(1,2,NA,4), c2 = c(NA,2,NA,5), c3 = c(NA,4,NA,NA), c4 = c(2,3,7,8)) # needs at least 4 non-missing values per row mean_n(dat, 4) # 1 valid return value #>  NA 2.75 NA NA # needs at least 3 non-missing values per row mean_n(dat, 3) # 2 valid return values #>  NA 2.75 NA 5.67 # needs at least 2 non-missing values per row mean_n(dat, 2) #>  1.50 2.75 NA 5.67 # needs at least 1 non-missing value per row mean_n(dat, 1) # all means are shown #>  1.50 2.75 7.00 5.67 # needs at least 50% of non-missing values per row mean_n(dat, .5) # 3 valid return values #>  1.50 2.75 NA 5.67 # needs at least 75% of non-missing values per row mean_n(dat, .75) # 2 valid return values #>  NA 2.75 NA 5.67