Hello, Can anyone help explain why the following are not equivalent? I have written a function called cord.mag(x,y) which takes two numbers and outputs a number. Further I defined m=1:5, n=1:26> for(i in m) { for (j in n) print(cord.mag(i,j))}this prints the m*n values, one on each line properly> outer(m,n,cord.mag)this gives me a matrix of zeroes> outer(1,2,cord.mag)this gives the right value on the other hand Thanks
K Fung <fungile at yahoo.com> writes:> > outer(m,n,cord.mag) > > this gives me a matrix of zeroes > > > outer(1,2,cord.mag) > > this gives the right value on the other handYour cord.mag function probably doesn't vectorize. Try Cord.mag <- function(m,n) mapply(cord.mag, m, n) outer(m, n, Cord.mag) -- 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