Learn R Programming

scanstatistics (version 1.0.1)

apply_rowwise: Apply a function to each row of a matrix.

Description

Apply a function to each row of a matrix. If the function returns a scalar, then return a vector. If the function returns a vector, return a matrix with the same number of rows.

Usage

apply_rowwise(A, .f, ...)

Arguments

A

A matrix.

.f

A function taking a vector as a first argument. This function should preferably return a vector of the same length as the first argument.

...

Other arguments passed to .f.

Value

In case .f returns a vector of length n, a matrix with nrow(A) rows and n columns is returned. If .f returns a scalar, a vector with nrow(A) elements is returned.