# Function to calculate the mode in Julia?

**URL:** <https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095>\
**Category:** General Usage\
**Tags:** statistics\
**Created:** [November 14, 2019, 6:13pm UTC](https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095 "2019-11-14T18:13:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [November 14, 2019, 6:13pm UTC](https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095/1 "2019-11-14T18:13:04Z")

</div>

I feel silly even asking this, but I can’t find the answer via google search for the life of me. Does Julia not have a function to calculate the mode of an array?

I’ve tried the code below in Julia 1.2 and Julia 1.3-rc4

```julia
using Statistics
mode([1,2,2,2,2,3,4])

```

and it results in `ERROR: UndefVarError: mode not defined`

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [November 14, 2019, 6:16pm UTC](https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095/2 "2019-11-14T18:16:31Z")

</div>

Hi, there is one in [`StatsBase.jl`](https://juliastats.org/StatsBase.jl/v0.20/index.html): `StatsBase.mode`.

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [November 14, 2019, 6:29pm UTC](https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095/3 "2019-11-14T18:29:02Z")

</div>

Thanks very much! Do you know if StatsBase is intending to take the place of Statistics?

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [November 14, 2019, 8:30pm UTC](https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095/4 "2019-11-14T20:30:57Z")

</div>

Functionality from StatsBase will eventually be folded into Statistics or other packages. Don’t know if overall plan is documented, but it’s mentioned here:

[https://github.com/JuliaStats/StatsBase.jl/issues/493#issuecomment-490213594](https://github.com/JuliaStats/StatsBase.jl/issues/493#issuecomment-490213594)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 15, 2019, 7:13am UTC](https://discourse.julialang.org/t/function-to-calculate-the-mode-in-julia/31095/5 "2019-11-15T07:13:46Z")

</div>

I hope not. This may not be apparent to users who don’t contribute to `Base` or the standard libraries, but maintaining code in either is much more involved than in a package: you are tied to the release cycle of Julia, you cannot make breaking changes, only extensions (until Julia 2.0).

From the user perspective, only very important bugfixes are backported to `1.0.*`, so effectively even conservative users have to go with the later release if the want a feature.
