Search code examples
rmedian

Computing Median. Where is the error?


I want to compute median of the following density. But it's not working.

  f <- function(x)(3/7)*x^2

  r <- rep(0,5000)
  x=seq(1,2,length=5000)

 for(i in 1:5000){
    r[i]=integrate(f,lower=1,upper=x[i])$value
  }

 d <- data.frame(x,r)
 med <- d$x[d$r==0.5]
 med

Solution

  • No elements of d$r equal exactly 0.5. I suspect that you need something like:

    med <- d$x[d$r>=0.5 & d$r <=0.501]