The curve() function is being (overly?) clever in allowing nonstandard
evaluation to let you specify an expression for the function argument. For
integrate(), you need to go the standard way and set up an actual function of 1
argument and pass that. It's not all that hard:
> f <- function(x) x*
On 21.02.2017 18:29, C W wrote:
Dear R list,
I am having a little trouble understanding the R code. I want to compute
expectation of normal pdf.
I did the following:
integrate(x*dnorm(x, rate=1), -Inf, Inf)
integrate needs a function as first argument, hence:
integrate(function(x) x*dno
Dear R list,
I am having a little trouble understanding the R code. I want to compute
expectation of normal pdf.
I did the following:
integrate(x*dnorm(x, rate=1), -Inf, Inf)
Error in match.fun(f) : object 'x' not found
If I did this, I get,
integrate(dexp(x, rate=1), -Inf, Inf)
Error in dexp(x
3 matches
Mail list logo