Skip to content
Prev 11164 / 398502 Next

outer

Peter Holzer <holzer at stat.math.ethz.ch> writes:
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)