Learn R Programming

rmngb (version 0.6-1)

outerList: Outer Product of Lists

Description

The outer product of the lists X and Y is the matrix M with dimension c(length(X), length(Y)) where element M[i, j] = FUN(X[[i]], Y[[j]]).

Usage

outerList(X, Y, FUN, ...)

Arguments

X
a list.
Y
a list.
FUN
a function to use on the outer product, taking elements of X and Y as arguments.
...
additional arguments passed to FUN.

Value

A matrix with dimension c(length(X), length(Y)) where element M[i, j] = FUN(X[[i]], Y[[j]]).

Details

X and Y must be suitable arguments for FUN. Each will be extended by rep to length the products of the lengths of X and Y before FUN is called.

FUN is the applied to these two extended vectors by mapply.

When they exist, the names of X and Y will be used as rownames and colnames.

See Also

outer, mapply.

Examples

Run this code
a <- list(a = 1:3, b = 4:7, c = 8:9)
b <- list(x = 4:8, y = 0:1)
f <- function(x, y)
    any(match(x, y, nomatch = 0L) > 0L)

outerList(a, b, f)

Run the code above in your browser using DataLab