Skip to content
Prev 76715 / 398502 Next

problems with outer ( was Re: help )

[[ Please use a meaningful subject line. Thank you. ]]

Dominique,

I am unable to reproduce your example in R-2.1.1. Can you reproduce this
in a fresh session of R and state which version are you using ?

 u <- v <- seq(0, 1, length=30)
 f <- function(x, y){ cp=max(x+y-1,0) }
 z <- outer(u, v, f)
Error in outer(u, v, f) : dim<- : dims [product 900] do not match the
length ofobject [1]



As shown in the R FAQ 7.17 (http://tinyurl.com/amofj), you will need to
write a wrapper function. This works for me.

 wrapper <- function(x, y, my.fun, ...) {
      sapply(seq(along = x), FUN = function(i) f(x[i], y[i], ...))
  }
 z <- outer(u, v, wrapper)

dim(z)
[1] 30 30

range(z)
[1] 0 1


Regards, Adai
On Mon, 2005-09-05 at 14:06 +0200, Dominique Katshunga wrote: