Learn R Programming

fntl (version 0.1.1)

which0: Matrix Which Function

Description

Matrix Which Function

Usage

which0(X, f)

Value

A matrix with two columns. Each row contains a row and column index corresponding to an element of \(X\) that matches the criteria of \(f\). See section "Which" of the package vignette for details.

Arguments

X

A matrix

f

A predicate to apply to each element of \(X\).

Details

The which C++ functions are intended to operate like the following call in R.

which(f(X), arr.ind = TRUE) - 1

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.

Examples

Run this code
X = matrix(1:12 / 6, nrow = 4, ncol = 3)
f = function(x) { x < 1 }
which0(X, f)

Run the code above in your browser using DataLab