Last active
March 23, 2018 07:17
-
-
Save tk3369/8aded8faabf9432b08f2921bf754a3a3 to your computer and use it in GitHub Desktop.
groupby function that returns a Dict of indices
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see https://discourse.julialang.org/t/allocation-groupby/7505 | |
function groupby(v::AbstractVector{T}) where T | |
d = Dict{T,Vector{Int}}() | |
i = 1 | |
for x in v | |
if !haskey(d, x) | |
d[x] = [i] | |
else | |
push!(d[x], i) | |
end | |
i += 1 | |
end | |
d | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment