How can I choose columns from a StructArray?
julia> StructArray(a=[1,2], b=[10,20], c=[100, 200])[(:a,:b)]
ERROR: ArgumentError: invalid index: (:a, :b) of type Tuple{Symbol, Symbol}
How can I choose columns from a StructArray?
julia> StructArray(a=[1,2], b=[10,20], c=[100, 200])[(:a,:b)]
ERROR: ArgumentError: invalid index: (:a, :b) of type Tuple{Symbol, Symbol}
You can get a single column with A.a
, A.b
. For multiple columns I don’t know if there’s something better than [getproperty(A, c) for c in (:a, :b)]
or getproperty.(Ref(A), (:a, :b))
Ah actually there’s components
:
julia> A = StructArray(a=[1,2], b=[10,20], c=[100, 200])
2-element StructArray(::Vector{Int64}, ::Vector{Int64}, ::Vector{Int64}) with eltype @NamedTuple{a::Int64, b::Int64, c::Int64}:
(a = 1, b = 10, c = 100)
(a = 2, b = 20, c = 200)
julia> StructArrays.components(A)[(:a, :b)]
(a = [1, 2], b = [10, 20])
But it’s deprecated…