outer {base}R Documentation

Outer Product of Arrays

Description

The outer product of the arrays X and Y is the array A with dimension c(dim(X), dim(Y)) where element A[c(arrayindex.x, arrayindex.y)] = FUN(X[arrayindex.x], Y[arrayindex.y], ...).

Usage

outer(X, Y, FUN="*", ...)
X %o% Y

Arguments

X A vector or array.
Y A vector or array.
FUN a function to use on the outer products, it may be a quoted string.
... optional arguments to be passed to FUN.

Details

FUN must be a function (or the name of it) which expects at least two arguments and which operates elementwise on arrays.

Where they exist, the [dim]names of X and Y will be preserved.

%o% is an alias for outer (where FUN cannot be changed from "*").

Author(s)

Jonathan Rougier

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

See Also

%*% for usual (inner) matrix vector multiplication; kronecker which is based on outer.

Examples

x <- 1:9; names(x) <- x
# Multiplication & Power Tables
x %o% x
y <- 2:8; names(y) <- paste(y,":",sep="")
outer(y, x, "^")

outer(month.abb, 1999:2003, FUN = "paste")

## three way multiplication table:
x %o% x %o% y[1:3]

[Package base version 2.2.1 Index]