Mean function unknown

After adding and importing the Statistics package Julia still does not recognize the mean function, any ideas?

You did using Statistics? What about Statistics.m+tab? Does the completion list mean?

1 Like

Can you show exactly what you did and the version you’re on? I.e. in a new Julia REPL session do this:

julia> using Statistics

julia> mean(rand(10))

julia> versioninfo()
Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

Note that Statistics is a standard library, so you shouldn’t have to add it.


Also note that import and using do subtly different things: using brings everything that’s exported by the package into scope, but import does not:

julia> import Statistics

julia> mean
ERROR: UndefVarError: mean not defined

julia> using Statistics

julia> mean
mean (generic function with 5 methods)

With import, you have to specifically ask for the things you want to bring into scope (next example run in a clean session):

julia> import Statistics: mean

julia> mean
mean (generic function with 5 methods)

The reason that import works this way is that it allows you to add methods to (aka extend) to functions that it brings in, whereas using does not (you’d have to write Statistics.mean(x::MyType) = ...)

FWIW, I always use using, unless I’m extending a function many times and don’t want to preface it with the module name every time.


Thank you!

1 Like