Skip to content
Prev 10325 / 398503 Next

out of memory?

news_vkhamenya at chat.ru wrote:
I think the source of the confusion here is in how outer uses its FUN
argument, and hence how that function has to be written.  Here is an
example that should show what is happening:
+ cat("x = ", x, "\n")
+ cat("y = ", y, "\n")
+ x+y
+ }
x =  1 2 3 1 2 3 
y =  1 1 1 2 2 2 
     [,1] [,2]
[1,]    2    3
[2,]    3    4
[3,]    4    5
[instead of printing, you can also use debug(f) to see what is going on]

There is *one* call to FUN with arguments that are the appropriate
replications of X and Y, not 3*2=6 calls to FUN with scalar arguments.
This is done since one call to a vectorized function will be much
faster than many calls to functions working with scalar values.  The
help for outer hints at this but could be a bit more explicit on this
since it is a natural point of confusion.

As a result, as has been pointed out by others, outer isn't the right tool
for this problem.

Hope that helps.

luke
Message-ID: <200103221219.f2MCJQL15109@muskrat.stat.umn.edu>
In-Reply-To: <58957652691.20010322113006@chat.ru> from "news_vkhamenya@chat.ru" at "Mar 22, 2001 11:30:06 am"