Generalized Outer Products

DESCRIPTION:

Performs an outer product operation given two arrays (or vectors) and, optionally, a function.

USAGE:

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

REQUIRED ARGUMENTS:

X,Y
first and second arguments to the function FUN. Missing values ( NAs) are allowed if FUN accepts them.

OPTIONAL ARGUMENTS:

FUN
a S-PLUS function that takes at least two vectors as arguments and returns a single value. This may also be a character string giving the name of such a function.
...
other arguments to FUN, if needed. The names of the arguments, if any, should be those meaningful to FUN.

VALUE:

array, whose dimension vector is the concatenation of the dimension vectors of X and Y, and such that FUN(X[i,j,k,...], Y[a,b,c,...]) is the value of the [i,j,k,...,a,b,c,...] element. (Vectors are considered to be one-dimensional arrays.)

DETAILS:

outer forms two arrays corresponding to the data in X and Y, each of which has a dim attribute formed by concatenating the dim attributes of X and Y. It then calls FUN just once with these two arrays as arguments. Therefore, FUN should be a function that operates elementwise on vectors or arrays and expects (at least) two arguments.

SEE ALSO:

, .

EXAMPLES:

z <- x %o% y   # The outer product array 
  # dim(z) == c(dim(as.array(x)), dim(as.array(y))) 
 # simulate a two-way table 
outer(c(3.1, 4.5, 2.8, 5.2), c(2.7, 3.1, 2.8),"+") + matrix(rnorm(12), nrow=4) 
outer(month.name, 2001:2003, paste) # All month year combinations