Hello! I want to do this formula in R:

With k=1

Where F(x) is the distribution function of x and f(x) is the density function of x.

In my programming I called x emhi and x-T(x) edhi.

I did:

distx <- function (x){plnorm(x, meanlog=mean(log(emhi)), sdlog=sd(log(emhi)), lower.tail = TRUE, log.p = FALSE)}

densx <- function (x){dlnorm(x, meanlog=mean(log(emhi)), sdlog=sd(log(emhi)), log = FALSE)}n<-1

integral <- function(edhi) {

for (x in edhi) {

return (edhi[n]*(1-distx(emhi[n]))*densx(emhi[n]))

n=n+1

}

}

wy <- integrate(integral, 0, Inf)

print(wy)

However it's telling me "evaluation of function gave a result of wrong length".

Where is the mistake? How can I do it?

Thank you!!!