https://github.com/cran/pracma
Tip revision: 6bedfa382c05ccbdda30ab12438b32fd9ba13876 authored by HwB on 12 December 2012, 00:00:00 UTC
version 1.3.3
version 1.3.3
Tip revision: 6bedfa3
bsxfun.R
##
## b s x f u n . R
##
bsxfun <- function(f, x, y, ...) {
stopifnot(is.numeric(x), is.numeric(y))
fun <- match.fun(f)
f <- function(x, y) fun(x, y, ...)
dx <- dim(x); dy <- dim(y)
if ( is.vector(x) && is.vector(y) ) {
z <- mapply(f, x, y)
} else if (is.array(x) && is.array(y) && dx == dy) {
z <- mapply(f, x, y)
dim(z) <- dx
} else {
stop("Argument 'x', 'y' must be vectors or arrays of the same size.")
}
return(z)
}