Writing Multidimensional FreqTable to CSV

Here is an absolutely indecipherable method I just came up with. It will get the job done no matter the number of dimensions you are tabbing over

julia> function iteratenames(t)
           dns = (:count, dimnames(t)...)
           nms = names(t)
           out = map(vec(CartesianIndices(t))) do i
               val = t[i]
               indices = ntuple(length(nms)) do j
                  nms[j][i[j]]
               end
               vals = (val, indices...)
               NamedTuple{dns}(vals)
           end
           DataFrame(out)
       end
1 Like