Description Usage Arguments Details Value Author(s) See Also Examples
In the construction of psychometric scales the calculation of a value is
sometimes only desired if a minimum number of items contain values. In SPSS
it is possible to calculate a mean value only if a minimum number of values
are supplied by using the syntax MEAN.MIN with MIN being a numeric value. The
function rowMeans2
does the same.
1 |
x |
A matrix of dataframe whose columns should be averaged. |
w |
A numerical vector of weights the same length as number of columns
in |
min |
The minimum number of values required to calculate the mean value.
Otherwise return |
na.rm |
A logical value indicating whether |
rowMeans2
is very similary to rowMeans
. The differences are
that rowMeans2
allows to indicate the minimum number of values that
have to be supplied and to weight the columns.
A vector of means.
Mark Heckmann
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | x <- replicate(3, runif(5))
x[1:3, 1] <- NA # add NAs to data
x[1:2, 2] <- NA
x[1, 3] <- NA
x
rowMeans2(x) # the same as rowMeans, except that NAs are allowed
rowMeans2(x, min=2) # minimum two values to calculate mean
rowMeans2(x, min=3) # minimum three values to calculate mean
# returns numeric(0) if x has zero rows
d <- x[NULL, ]
rowMeans2(d)
# weights for each column
rowMeans2(x, w=c(1,1,2))
|
[,1] [,2] [,3]
[1,] NA NA NA
[2,] NA NA 0.32754336
[3,] NA 0.62029081 0.83242741
[4,] 0.4989461 0.03526793 0.20840393
[5,] 0.7293810 0.19558767 0.06468153
[1] NA 0.3275434 0.7263591 0.2475393 0.3298834
[1] NA NA 0.7263591 0.2475393 0.3298834
[1] NA NA NA 0.2475393 0.3298834
numeric(0)
[1] NA 0.3275434 0.7617152 0.2377555 0.2635829
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.