matrix_apply {fntl} | R Documentation |
Matrix Apply Functions
Description
Matrix Apply Functions
Usage
mat_apply(X, f)
row_apply(X, f)
col_apply(X, f)
Arguments
X |
A matrix |
f |
The function to apply. |
Details
The mat_apply
, row_apply
, and col_apply
C++ functions are intended to
operate like the following calls in R, respectively.
apply(x, c(1,2), f) apply(x, 1, f) apply(x, 2, f)
The R functions exposed here are specific to numeric-valued matrices, but the underlying C++ functions are intended to work with any type of Rcpp Matrix.
Value
mat_apply
returns a matrix. row_apply
and col_apply
return a vector.
See section "Apply" of the package vignette for details.
Examples
X = matrix(1:12, nrow = 4, ncol = 3)
mat_apply(X, f = function(x) { x^(1/3) })
row_apply(X, f = function(x) { sum(x^2) })
col_apply(X, f = function(x) { sum(x^2) })
[Package fntl version 0.1.1 Index]