Counting number of occurences in an array

Hi! An efficient way to do this is to use the counter function from DataStructures:

julia> using DataStructures

julia> c = counter([1,2,3,3,4,4,4,6])
Accumulator{Int64,Int64} with 5 entries:
  4 => 3
  2 => 1
  3 => 2
  6 => 1
  1 => 1

you can then use the keys(c) and values(c) to plot the number of occurrences.

13 Likes