[R] problems with outer (remainder of reply...)

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Sun May 7 11:44:38 CEST 2000


Bill Venables <Bill.Venables at cmis.csiro.au> writes:

> [2nd go.  My previous message was suddenly dispatched before I had
> finished.  Sorry about that - MicroSoft again, Sheesh!]
> 
> At 10:57 PM 5/6/00 -0400, Faheem Mitha wrote:
> 
> >
> >Cam some kind person in any case confirm that this is what was meant?
> >
> >f.vect <- function(x,y) sapply(seq(along=x),function(i)f(x[i],y[i]))
> >
> >seems to be to only work correctly if x and y are the same length.
> 
> Yes it will handle it, but it may not speed things up very much.
> 
> You can think of outer as first doing a special kind of recycling, (the
> same kind as is done in exapnd.grid in fact), calling the function you
> supply once with expanded vector arguments with equal length and
> re-arranging the result back into a matrix of the same form.

Or, which is what I left out: When coming from outer, x and y *will*
have the same length, so one doesn't have to worry about recycling
rules. What the function sees is not the original x,y, but e.g.

x1 y1
x2 y1
x1 y2
x2 y2
x1 y3
x2 y3

Try outer(1:2,1:3,function(x,y)print(paste(x,y)))

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list