kronecker
Generalized Kronecker Products

Description

Returns an array whose dimensions are the product of the dimensions of the input arrays which contains a function of all possible combinations of the input values.

Usage

kronecker(X, Y, FUN = "*", make.dimnames = FALSE, ...)
X %x% Y

Arguments

X, Y arrays with any number of dimensions. A vector is converted to a 1-dimensional array.
FUN a function (or the name of a function) of at least 2 arguments that maps vectors of the elements of the X and Y arrays to an output vector of the same length. By default, this is the multiplication function giving the usual Kronecker product.
make.dimnames a logical value. If TRUE, specifies that the dimnames of the output should be constructed from the dimnames of the inputs. By default, FALSE.
... other arguments to pass to the the function FUN.

Details

The X %x% Y syntax is shorthand for kronecker(X, Y, FUN="*").
Value
returns an array with dimensions dim(X) * dim(Y). The i,j,... block of size dim(Y) in the return value is FUN(X[i,j,...], Y).
Background
Kronecker products are often used in multivariate statistics.
See Also
Matrix-product, outer, cbind, array.
Examples
kronecker(matrix(1:6,3,2), diag(2))
matrix(1:6,3,2) %x% diag(2)   # the same
# still the same
kronecker(matrix(1:6,3,2), diag(2), function(x, y) x * y)   

kronecker( array(1:6,c(2,1,3),list(paste0("R",1:2),paste0("C",1),paste0("Strata",1:3))), matrix(c(100,200), nrow=1, ncol=2, dimnames=list(NULL,c("1H","2H"))), FUN=`+`, make.dimnames=TRUE)

Package base version 6.1.1-7
Package Index