nalimilan / FreqTables.jl

Frequency tables in Julia
Other
89 stars 19 forks source link

Better interaction with tables? #71

Open pdeffebach opened 7 months ago

pdeffebach commented 7 months ago

I just wrote the following function on discourse which converts an arbitrary NamedArray to a DataFrame

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

We could probably implement a small conversion to something that satisfied the Tables.jl interface and make it easier for people to do crosstabs that return tables.

bkamins commented 7 months ago

Indeed it is often more useful to have a DataFrame everywhere in the pipeline