Function to calculate the mode in Julia?

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

using Statistics

and it results in ERROR: UndefVarError: mode not defined

Thanks for any help.

Hi, there is one in StatsBase.jl: StatsBase.mode.


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

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:


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.