[R] Bug with curve?
Alberto Monteiro
albmont at centroin.com.br
Fri Feb 1 15:21:27 CET 2008
Paul Smith wrote:
>
>> f <- function(x) exp(-x)*x-0.05
>> g <- function(x) 0
>> curve(f,0,5)
>> curve(g,add=T)
>> Error in xy.coords(x, y) : 'x' and 'y' lengths differ
>>
>
> However, with
>
> g <- function(x) x-x
>
> no error is generated.
>
> Is this a bug?
>
No; simplify it:
g1 <- function(x) 0
g2 <- function(x) x - x
g1(anything) will return (scalar) 0
g2(scalar) will return (scalar) 0, g2(vector) will return
(vector) 0, g2(matrix) will return (matrix) 0.
So, in your original problem, f and (first) g have different
behaviours.
Alberto Monteiro
More information about the R-help
mailing list