Dear R and S People: First, thank you to so many people for your help to my problem. Here is the solution: a <- 0.5*(outer(1:n3,1:n3,function(x,y,n2.){n2. - pmax(x,y)},n2.=n2)) I have one final pesky question, please: During my experiments, I tried the following: a <- 0.5*(outer(1:n3,1:n3,function(x,y,n2.=n2){n2. - pmax(x,y)})) Why doesn't this work please? thank you! Sincerely, Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: hodgess at gator.uhd.edu
Erin Hodgess <hodgess at gator.uhd.edu> writes:> a <- 0.5*(outer(1:n3,1:n3,function(x,y,n2.=n2){n2. - pmax(x,y)})) > Why doesn't this work please?Because defaults are expressions to be evaluated in the function's evaluation frame (i.e. the expression could depend on x and y for instance). When you evaluate the function, it goes looking for n2 -- and you're back to square one, basically. You might use substitute to poke a precomputed n2 into the function definition, but it isn't pretty. -- 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