Single value in DataFrame-structure

I use a variable v to index one or more columns of a DataFrame. Sometimes v is a Symbol and sometimes v is an array of symbols. Is there a single syntax to always return the value(s) in a DataFrame-structure, even when v is a Symbol? So I essentially want df[row, [v]] when v is a Symbol and df[row,v] when v is an array of Symbols.

julia> df = DataFrame(x=1, y=2)
1×2 DataFrame
│ Row │ x │ y │
├─────┼───┼───┤
│ 1   │ 1 │ 2 │

julia> v = :x
:x

julia> df[1,v]
1

julia> df[1,[v]]
1×1 DataFrame
│ Row │ x │
├─────┼───┤
│ 1   │ 1 │

julia> v = [:x, :y]
2-element Array{Symbol,1}:
 :x
 :y

julia> df[1,v]
1×2 DataFrame
│ Row │ x │ y │
├─────┼───┼───┤
│ 1   │ 1 │ 2 │

julia> df[1,[v]]
ERROR: ArgumentError: idx[1] has type Array{Symbol,1}; DataFrame only supports indexing columns with integers, symbols or boolean vectors

Maybe use vcat for that:

julia> vcat(:y)
1-element Array{Symbol,1}:
 :y

julia> vcat([:y])
1-element Array{Symbol,1}:
 :y
1 Like

That works - thanks!