rowVars | R Documentation |
Calculates variances of each row of an array
rowVars(x, na.rm = TRUE)
x |
Array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame. |
na.rm |
Logical. Should missing values (including NaN) be omitted from the calculations? |
This function is the same as applying apply with FUN=var but is a lot faster.
A numeric or complex array of suitable size, or a vector if the result is one-dimensional. The dimnames (or names for a vector result) are taken from the original array.
## The function is currently defined as function (x,na.rm = TRUE) { sqr = function(x) x * x n = rowSums(!is.na(x)) n[n <= 1] = NA return(rowSums(sqr(x - rowMeans(x,na.rm = na.rm)), na.rm = na.rm)/(n - 1)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.