Learn R Programming

expandFunctions (version 0.1.0)

eOuter: Extend outer product.

Description

Extends outer {base} outer(x,y,FUN) to include functions FUN(x,y,...) where the first argument of FUN is a vector but the second argument must be a scalar.

Usage

eOuter(x, y, FUN, ...)

Arguments

x
Vector, with the same function as in outer {base}. Each value will correspond to a row in the return matrix.
y
Vector. Each element in the vector corresponds to a column in the return matrix.
FUN
Function. x and y will be the first and second arguments. Unlike outer, however, while a vector can be the first argument, FUN might only allow one value as the second argument. This means eOuter can use lagshift, for instance, as FUN.
...
Additional parameters for FUN.

Value

A matrix Z of size length(x) X length(y) containing Z[,i] with values FUN(x,y[i],...).

Details

outer has limitations; it only works with functions which can take vector inputs for both the first and second arguments, such as "^". As a result, many functions cannot be used for FUN. The function eOuter gets around this limitation by additionally allowing functions which accept a vector for the first argument, but only scalars for the second argument. It can be used everywhere that outer can be used, but also when FUN is limited in this way.

See Also

outer and ePow

Examples

Run this code
# This implements a function similar to ePow
# FIXME: change ePow to use eOuter!!!
eOuter(1:6,0:2,FUN = `^`)
# Other functions of columns
eOuter(1:10,0:3,FUN = lagshift,lagMax=3,pad=NA)
# FIXME: Make function to allow polynomials to be used:
# eOuter(1:10,1:3,FUN = glaguerre.polynomials, alpha=0.5)

Run the code above in your browser using DataLab