Learn R Programming

matrixStats (version 0.12.2)

rowVars: Variance estimates for each row (column) in a matrix

Description

Variance estimates for each row (column) in a matrix.

Usage

rowVars(x, na.rm=TRUE, center=NULL, dim.=dim(x), ...)
 colVars(x, na.rm=TRUE, center=NULL, dim.=dim(x), ...)

Arguments

x
center
(optional) The center, defaults to the row means.
na.rm
If TRUE, NAs are excluded first, otherwise not.
dim.
An integer vector of length two specifying the dimension of x, also when not a matr
...
Additional arguments passed to rowMeans() and rowSums().

Value

See Also

See rowMeans() and rowSums() in colSums().

Examples

Run this code
set.seed(1)

x <- matrix(rnorm(20), nrow=5, ncol=4)
print(x)

# Row averages
print(rowMeans(x))
print(rowMedians(x))

# Column averages
print(colMeans(x))
print(colMedians(x))


# Row variabilities
print(rowVars(x))
print(rowSds(x))
print(rowMads(x))
print(rowIQRs(x))

# Column variabilities
print(rowVars(x))
print(colSds(x))
print(colMads(x))
print(colIQRs(x))


# Row ranges
print(rowRanges(x))
print(cbind(rowMins(x), rowMaxs(x)))
print(cbind(rowOrderStats(x, 1), rowOrderStats(x, ncol(x))))

# Column ranges
print(colRanges(x))
print(cbind(colMins(x), colMaxs(x)))
print(cbind(colOrderStats(x, 1), colOrderStats(x, nrow(x))))


x <- matrix(rnorm(2400), nrow=50, ncol=40)

# Row standard deviations
d <- rowDiffs(x)
s1 <- rowSds(d)/sqrt(2)
s2 <- rowSds(x)
print(summary(s1-s2))

# Column standard deviations
d <- colDiffs(x)
s1 <- colSds(d)/sqrt(2)
s2 <- colSds(x)
print(summary(s1-s2))

Run the code above in your browser using DataLab