mode() , "numeric". "" , .. . . ?mode , R .
:
> set.seed(1)
> dat <- sample(1:5, 100, replace = TRUE)
> (tab <- table(dat))
dat
1 2 3 4 5
13 25 19 26 17
> which.max(tab)
4
4
> tab[which.max(tab)]
4
26
- , (PDF) . , PDF, .
, :
> sepalwd <- with(iris, density(Sepal.Width))
> plot(sepalwd)
> str(sepalwd)
List of 7
$ x : num [1:512] 1.63 1.64 1.64 1.65 1.65 ...
$ y : num [1:512] 0.000244 0.000283 0.000329 0.000379 0.000436 ...
$ bw : num 0.123
$ n : int 150
$ call : language density.default(x = Sepal.Width)
$ data.name: chr "Sepal.Width"
$ has.na : logi FALSE
- attr(*, "class")= chr "density"
> with(sepalwd, which.max(y))
[1] 224
> with(sepalwd, x[which.max(y)])
[1] 3.000314
. ?density. density() n = 512 . , :
> sepalwd2 <- with(iris, density(Sepal.Width, n = 2048))
> with(sepalwd, x[which.max(y)])
[1] 3.000314
.