matrix_apply | R Documentation |
Matrix Apply Functions
mat_apply(X, f)
row_apply(X, f)
col_apply(X, f)
X |
A matrix |
f |
The function to apply. |
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.
mat_apply
returns a matrix. row_apply
and col_apply
return a vector.
See section "Apply" of the package vignette for details.
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) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.