[R] how to calculate the mode of a continuous variable
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Fri Aug 29 13:37:31 CEST 2008
Henrique Dallazuanna wrote:
> Try:
>
> as.numeric(names(which.max(table(x))))
>
> On Fri, Aug 29, 2008 at 3:13 AM, Manuel Ramon <manugen at gmail.com> wrote:
>
You missed the word "continuous" there...
> x <- rnorm(10)
> table(x)
x
-1.64244637710945 -0.836534097622312 -0.810292826933485 -0.721008996586432
1 1 1 1
-0.679702422788255 -0.667735659553467 -0.263432175981501 0.0795699932826675
1 1 1 1
0.387151850978792 0.761964511475389
1 1
> as.numeric(names(which.max(table(x))))
[1] -1.642446
Instead, how about
> dd <- density(x)
> which.max(dd$y)
[1] 227
> dd$x[which.max(dd$y)]
[1] -0.6938049
> plot(dd)
> rug(x)
> abline(v=dd$x[which.max(dd$y)])
>
>> Is there any R funtion that allow the estimation of mode in a continuous
>> variable?
>> Thank you
>> --
>> View this message in context:
>> http://www.nabble.com/how-to-calculate-the-mode-of-a-continuous-variable-tp19214243p19214243.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list