# computing mode of a density function in R

#### Cynderella

##### New Member
I want to compute mode of the following distribution in R.
But i think my procedure is not correct to compute it .

Code:
f <- function(x)(3/7)*x^2 #1<x<2
x=seq(1,2,length=5000)
y = f(x)
d = data.frame(x,y)
d$x[d$y==max(d\$y)]

#### Dason

##### Ambassador to the humans
It seems correct enough in general and it's definitely correct for this case (your function is increasing over the positive reals so the max occurs at the largest x-value you consider).