Re: [R] ifelse(logical, function1, function2) does not work

2006-10-09 Thread Thomas Lumley
On Sat, 7 Oct 2006, Rolf Turner wrote: > Peter Dalgaard writes: > >> Alberto Vieira Ferreira Monteiro <[EMAIL PROTECTED]> writes: >> >>> Why this kind of assignment does not work? >>> >>> n <- 1 >>> f <- ifelse(n == 1, sin, cos) >>> f(pi) >> >> It's not supposed to. >> >> 'ifelse' retur

Re: [R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Gabor Grothendieck
I have noticed that dispatch on functions seems not to work in another case too. We define + on functions (I have ignored the niceties of sorting out the environments as we don't really need it for this example) but when we try to use it, it fails even though in the second example if we run it exp

Re: [R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Rolf Turner
Peter Dalgaard writes: > Alberto Vieira Ferreira Monteiro <[EMAIL PROTECTED]> writes: > > > Why this kind of assignment does not work? > > > > n <- 1 > > f <- ifelse(n == 1, sin, cos) > > f(pi) > > It's not supposed to. > > 'ifelse' returns a value with the same shape as 'test' whi

Re: [R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Peter Dalgaard
Alberto Vieira Ferreira Monteiro <[EMAIL PROTECTED]> writes: > Why this kind of assignment does not work? > > n <- 1 > f <- ifelse(n == 1, sin, cos) > f(pi) It's not supposed to. 'ifelse' returns a value with the same shape as 'test' which is filled with elements selected from

Re: [R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Gabor Grothendieck
Try n <- 1 f <- if (n == 1) sin else cos f(pi) On 10/7/06, Alberto Vieira Ferreira Monteiro <[EMAIL PROTECTED]> wrote: > Why this kind of assignment does not work? > > n <- 1 > f <- ifelse(n == 1, sin, cos) > f(pi) > > this must be rewritten as: > > n <- 1 > f <- cos > if (n == 1) f <- sin

[R] ifelse(logical, function1, function2) does not work

2006-10-07 Thread Alberto Vieira Ferreira Monteiro
Why this kind of assignment does not work? n <- 1 f <- ifelse(n == 1, sin, cos) f(pi) this must be rewritten as: n <- 1 f <- cos if (n == 1) f <- sin f(pi) [oops. 1.224606e-16 instead of zero. Damn floating point errors :-/] Alberto Monteiro _