Hi all, I tried to use outer() but it gave me wrong answer. Anyone can tell me why? Thank you for your time.> outer(a[1],b[1:2],f)[,1] [,2] [1,] 6903.15 6903.15 where> a[1] 0.5 2.0 4.0> b[1] -0.5 -1.5> ffunction(a1,b1){mleop4.fun(c(a1,b1,A[1],B[1],f1[1],f2[1],g[1],h[1]))} The answer should be 6869.808, 6809.302 as shown below:> outer(a[1],b[1],f)[,1] [1,] 6869.808> outer(a[1],b[2],f)[,1] [1,] 6809.302 Or> f(a[1],b[1])[1] 6869.808> f(a[1],b[2])[1] 6809.302>Nancy -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 14 Feb 2002, Nancy Lo wrote:> Hi all, > > I tried to use outer() but it gave me wrong answer. Anyone can tell me > why? Thank you for your time. > > > > outer(a[1],b[1:2],f) > [,1] [,2] > [1,] 6903.15 6903.15 > > where > > a > [1] 0.5 2.0 4.0 > > b > [1] -0.5 -1.5 > > > f > function(a1,b1){mleop4.fun(c(a1,b1,A[1],B[1],f1[1],f2[1],g[1],h[1]))} >It's a bit hard to tell without knowing what the function does, but it looks very much as if f() isn't vectorised. As help(outer) says `FUN' must be a function (or the name of it) which expects at least two arguments and which operates elementwise on arrays. and the workaround is in the FAQ. -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._