Search code examples
rcurve

curve works for some object but not other


I'm baffled why #1 would work while #2 wouldn't?

x=rnorm(100);curve(dnorm(x))

y=rnorm(100);curve(dnorm(y))
Error in curve(dnorm(y)) : 'expr' must be a function, or a call or an expression containing 'x'

Solution

  • Because curve() is somewhat magic and by default requires an expression written as a function of x (literally): from ?curve.

    expr: The name of a function, or a call or an expression written as a function of ‘x’ which will evaluate to an object of the same length as ‘x’.

    You could use

    curve(dnorm(y),xname="y")
    

    I have to warn you that the x and y values you are defining via rnorm() in your code are being ignored completely. (You could edit your question to explain better what you're trying to do ...)