Learn R Programming

houba (version 0.1.0)

apply: Apply functions over margins of a mmatrix

Description

This method generalizes `base::apply` to mmatrix objects

Usage

# S4 method for mmatrix
apply(X, MARGIN, FUN, ..., simplify = TRUE)

Value

If 'simplify' is TRUE, a matrix (or a mmatrix) or a vector (or a mvector). If 'simplify' is FALSE, a list.

Arguments

X

a mmatrix

MARGIN

an integer giving the subscript which the function will be applied over

FUN

the function to be applied

...

extra arguments for `FUN`

simplify

a logical indicating whether the results should be simplified

Details

If 'simplify' is TRUE the result will be a vector or a matrix, depending on the size of the values returned by 'FUN'. If the size of this object is greater than houba(max.size), then it will be memory-mapped (i.e., either a mvector or a mmatrix). If 'simplify' is FALSE, the result is a list.

The function extracts the rows or the columns of 'X' one by one, to a R object, which is passed to 'FUN'.

See Also

Examples

Run this code
a <- matrix(1:6, 2, 3)
A <- as.mmatrix(a)
apply(A, 1, var)
apply(A, 2, var)

Run the code above in your browser using DataLab