# Mean function unknown

**URL:** <https://discourse.julialang.org/t/mean-function-unknown/26844>\
**Category:** Statistics\
**Created:** [July 26, 2019, 12:46pm UTC](https://discourse.julialang.org/t/mean-function-unknown/26844 "2019-07-26T12:46:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [July 26, 2019, 12:46pm UTC](https://discourse.julialang.org/t/mean-function-unknown/26844/1 "2019-07-26T12:46:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [July 26, 2019, 12:48pm UTC](https://discourse.julialang.org/t/mean-function-unknown/26844/2 "2019-07-26T12:48:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 26, 2019, 1:29pm UTC](https://discourse.julialang.org/t/mean-function-unknown/26844/3 "2019-07-26T13:29:02Z")

</div>

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

```julia
julia> using Statistics

julia> mean(rand(10))
0.43470979652830044

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
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

```

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

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [July 29, 2019, 3:08pm UTC](https://discourse.julialang.org/t/mean-function-unknown/26844/4 "2019-07-29T15:08:14Z")

</div>

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
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
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.

---

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [July 30, 2019, 4:57pm UTC](https://discourse.julialang.org/t/mean-function-unknown/26844/5 "2019-07-30T16:57:15Z")

</div>

Thank you!
