| outer | R Documentation |
The outer product of the arraysX andY is the arrayA with dimensionc(dim(X), dim(Y)) where elementA[c(arrayindex.x, arrayindex.y)] = FUN(X[arrayindex.x], Y[arrayindex.y], ...).
outer(X, Y, FUN = "*", ...)X %o% Y
X, Y | First and second arguments for function |
FUN | a function to use on the outer products, foundvia |
... | optional arguments to be passed to |
X andY must be suitable arguments forFUN. Eachwill be extended byrep to length the products of thelengths ofX andY beforeFUN is called.
FUN is called with these two extended vectors as arguments(plus any arguments in...). It must be a vectorizedfunction (or the name of one) expecting at least two arguments andreturning a value with the same length as the first (and the second).
Where they exist, the [dim]names ofX andY will becopied to the answer, and a dimension assigned which is theconcatenation of the dimensions ofX andY (or lengthsif dimensions do not exist).
FUN = "*" is handled as a special caseviaas.vector(X) %*% t(as.vector(Y)), and is intended only fornumeric vectors and arrays.
%o% is binary operator providing a wrapper forouter(x, y, "*").
Jonathan Rougier
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)The New S Language.Wadsworth & Brooks/Cole.
%*% for usual (inner) matrix vectormultiplication;kronecker which is based onouter;Vectorize for vectorizing a non-vectorized function.
x <- 1:9; names(x) <- x# Multiplication & Power Tablesx %o% xy <- 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]
Add the following code to your website.
For more information on customizing the embed code, readEmbedding Snippets.
