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
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
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
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
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
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
_