davidavdav / NamedArrays.jl

Julia type that implements a drop-in replacement of Array with named dimensions
Other
120 stars 20 forks source link

is there an easy way to convert NamedArray to Dict #61

Closed mandarup closed 6 years ago

mandarup commented 6 years ago

This is how I am doing this now:

freqdict = Dict(name=> (namedarray)[name] 
                for name in names(namedarray)[1])

Question 1: is this the best way to achieve this

Question 2: Is this even necessary ..

davidavdav commented 6 years ago

A FreqTable can be multi-dimensional. But if you're interested only in the case of a 1-dim contingency table, you could indeed write

Dict(n::NamedVector) = Dict(name => n[name] for name in names(n, 1))

But I don't really see the point---you can just access the freqtable n in the same way as the constructed Dict.

mandarup commented 6 years ago

@davidavdav I needed to feed the dict to another function from another package which wouldn't accept the FreqTable type.

davidavdav commented 6 years ago

I've added the definition above in the code, so that in future releases this will be available.