[R] A problem with using the "outer" function

Thomas Lumley tlumley at u.washington.edu
Thu Jul 10 17:33:52 CEST 2003


On Wed, 9 Jul 2003, Duncan Murdoch wrote:

> On Wed, 09 Jul 2003 15:33:11 -0400, Ravi Varadhan <rvaradha at jhsph.edu>
> wrote :
>
> >Hi:
> >
> >I am using R 1.7.0 on Windows.  I am having trouble getting "outer" to
> >work on one of my functions.
>
> Most likely the problem is that the function you give doesn't work on
> array arguments.  Your function needs to take two arrays of the same
> shape as the first two arguments, and return an array of answers.
> outer() doesn't work by looping, it works by constructing big arrays
> of inputs and making just one function call.


Two further notes:

1/ This is in the FAQ.

2/ It is possible to use mapply() to vectorise an arbitrary function.
There isn't any speed advantage in doing so, but it will then work with
outer().

	-thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list