metaMA (version 3.1.2)

rowVars: Row variance of an array

Description

Calculates variances of each row of an array

Usage

rowVars(x, na.rm = TRUE)

Arguments

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?

Value

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.

Details

This function is the same as applying apply with FUN=var but is a lot faster.

Examples

Run this code
# NOT RUN {
## 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))
  }
# }

Run the code above in your browser using DataLab