Learn R Programming

fastR (version 1.1)

Column-wise variances and standard deviations: Colum-wise variances and standard deviations of a matrix

Description

Colum-wise variances and standard deviations of a matrix

Usage

colVars(x, suma = NULL, std = FALSE)

Arguments

x
A matrix with the data.
suma
If you already have the column sums vector supply it, otherwise leave it NULL.
std
A boolean variable specyfying whether you want the variances (FALSE) or the standard deviations (TRUE) of each column.

Value

A vector with the colum variances or standard deviations.

Details

We found this in stackoverflow and was created by David Arenburg. We then modified the function to match the sums type formula of the variance, which is faster.

See Also

cova, cora

Examples

Run this code
x <- matrix( rnorm(100 * 10000), ncol = 10000 )
system.time( apply(x, 2, var) )
system.time( colVars(x) )
a1 <- apply(x, 2, var)
a2 <- colVars(x)
all.equal(a1, a2)

Run the code above in your browser using DataLab