Stream: helpdesk (published)

Topic: ✔ missing weigths function in toy mean example


view this post on Zulip pryumin (Jul 28 2023 at 18:17):

Trying to follow a simple example from documentation for mean(x, weights(w)) (https://juliastats.org/StatsBase.jl/v0.23/means.html ) and encountering an error that weights function is missing.

Here is a complete example:

using Statistics
a = [1,2,3]
w = [3,4,5]
x = mean(a, weights(w))

and an error message

ERROR: UndefVarError: `weights` not defined
Stacktrace:
 [1] top-level scope

What can be wrong?

view this post on Zulip Leandro Martínez (Jul 28 2023 at 18:40):

This is an example of the StatsBase package, not of Base.Statistics:

julia> using StatsBase

julia> a = [1,2,3];

julia> w = [3,4,5];

julia> mean(a, weights(w))
2.1666666666666665

view this post on Zulip Sundar R (Jul 28 2023 at 18:49):

Also, just in case it isn't intentional, note that you're looking at the docs for a pretty old version of StatsBase. You can change to the current stable version's docs by clicking on the version number below the package name top left:
Screenshot_20230729_001526.png

Doesn't change anything for this particular function, just letting you know since search engines sometimes lead people to these older versions when they're looking for current docs.

view this post on Zulip pryumin (Jul 28 2023 at 19:11):

Ok, this of course solved the issue! Thanks! And thanks for the tip on current documentation

view this post on Zulip Notification Bot (Jul 28 2023 at 19:11):

pryumin has marked this topic as resolved.


Last updated: Nov 22 2024 at 04:41 UTC