# Very simple statistic needed

I have a very simple task: I have a list of CAN bus addresses like this:

``````1236454-element Vector{Union{Missing, Int64}}:
65
65
48
48
49
49
50
50
⋮
57
65
58
58
65
59
59
``````

Because all numbers are below 128 their can be max 128 different elements, in reality less.

I would like to know:
a. which value appears how often
b. perhaps a histogram

I could write that from the scratch, but I guess some library functions might help.

Any suggestions?

I think you want StatsBase.countmap().

3 Likes

Thanks. That is working nicely!

Only question that remains is how to plot the resulting dictionary as histogram…

Check out StatsPlots.jl

``````julia> cm = countmap(rand(1:5, 100))
Dict{Int64, Int64} with 5 entries:
5 => 29
4 => 17
2 => 20
3 => 14
1 => 20

julia> histogram(cm)
``````

EDIT: I just realized it plots the “transpose” of what you probably want Just calling `Plots.histogram` also works

``````histogram(rand(1:5, 100))
``````

Not yet working for me, I guess because the type of the vector is

``````Vector{Union{Missing, Int64}}
``````

EDIT:
This code works:

``````a = collect(skipmissing((ds.NodeID)))
Plots.histogram(a)
``````
2 Likes

Yes. There is an issue here tracking things.