Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

Apply.fun

Apply Functions Over Array Margins, using custom vecorization (possibly using parallel)


Description

Emulate parallel apply on a function, from mclapply. Returns a vector or array or list of values obtained by applying a function to margins of an array or matrix.

Usage

Apply.fun(FUN, X, MARGIN = 1, .combine = c, .lapply = parallel::mclapply, ...)

Arguments

FUN

function to apply on X

X

array of input values for FUN

MARGIN

1 indicates to apply on rows (default), 2 on columns

.combine

how to combine results (default using c(.))

.lapply

how to vectorize FUN call (default is parallel::mclapply)

...

optional arguments to FUN.

Value

array of values taken by FUN on each row/column of X

Examples

X = matrix(runif(10),ncol=2);
  rowSums(X) == apply(X,1,sum)
  apply(X,1,sum) == Apply.fun(sum,X)

X = matrix(runif(10),ncol=1)
  rowSums(X) == apply(X,1,sum)
  apply(X,1,sum) == Apply.fun(sum,X)

X = matrix(runif(10),ncol=2)
f = function(X) X[1]/X[2]
apply(X,1,f) == Apply.fun(f,X)

DiceView

Methods for Visualization of Computer Experiments Design and Surrogate

v2.0-1
GPL-3
Authors
Yann Richet, Yves Deville, Clement Chevalier
Initial release
2020-11-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.