What's the function to return the number of unique elements in an Array in Julia?
In R you have length(unique(x))
. I can do the same in Julia but there should be a more efficient way I think.
If you want an exact answer length(unique(x))
is as efficient as it gets for general objects. If your values have a limited domain, eg UInt8
, it may be more efficient to use a fixed size table. If you can accept an approximation, then you can use the HyperLogLog data structure / algorithm, which is implemented in the OnlineStats package:
https://joshday.github.io/OnlineStats.jl/latest/api/#OnlineStats.HyperLogLog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With