[R] outer
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu May 10 11:27:19 CEST 2001
Peter Holzer <holzer at stat.math.ethz.ch> writes:
> Hello Sean
>
> When using outer you need vectorized functions. I think in your case it
> would be enough to change the last line of your function to
>
> ifelse(r==0, y, gcd(y,r))
Nope. Since ifelse() evaluates both alternatives, you'll have an
unterminating recursion. The only sure-kill way is to do an explicit
vectorization:
gcd.v <- function(x,y) sapply(seq(along=x),function(i)gcd(x[i],y[i]))
outer(1:5,1:5, gcd.v)
--
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