Hi all,

I found some strange behaviour and am trying to find out where I'm going 
wrong. I have a dict that stores several vectors of equal length, and I 
want to make a DataFrame from it, where the columns should have the names 
of the dict keys:

using DataFrames

function collectFields(dict::Dict)
    di_keys = collect(keys(dict))
    cols = [ dict[k] for k in di_keys ]
    cnames = Array(Symbol,length(dict))
    for i in 1:length(di_keys)
        cnames[i] = symbol(di_keys[i])
    end
      return DataFrame(cols, cnames)
end

di = ["a"=>[1,3],"b"=>[0.0,1.0]]
collectFields(di)

This works as expected:

collectFields(di)
2x2 DataFrame
|-------|---|-----|
| Row # | a | b   |
| 1     | 1 | 0.0 |
| 2     | 3 | 1.0 |

however, changing the type of the vectors in dict:

di2 = ["a"=>[1,3],"b"=>[0,1]]


julia> collectFields(di2)
2x2 DataFrame
|-------|-------|----|
| Row # | x1    | x2 |
| 1     | [1,3] | a  |
| 2     | [0,1] | b  |


Any ideas? thanks!

Reply via email to