Adding columns based on unique values

If you work with relatively complex data frames, there are tools for such things in packages like Query. But you can also use plain operations from base Julia.

In Matlab you are encouraged to use things like splitapply etc. to vectorize such operations, but in Julia you have not to be afraid of using for loops, if they are the natural choice for what you want to do.

You could do, for instance:

inds = unique(A[:,1])
n, m = size(A)
res = zeros(eltype(A), length(inds), m) 
res[:,1] .= inds # first column of `res` is the list of unique values
for i = 1:n
    # look for the row in `res` where you want to add the value
    row = findfirst(j -> j == A[i,1], inds)
    for col = 2:m
        res[row, col] += A[i,col]
    end
end
res