function [marg_data,J] = marginalize(data, coords)

[n, m] = size(data);

[marg_data,I,J] = unique(data(:,coords),'rows');
n_marg = size(marg_data,1);
marg_count = zeros([n_marg 1]);

for k = 1:n
        marg_count(J(k)) = marg_count(J(k)) + data(k,end);
end

marg_data = [marg_data marg_count];
