"Vector{NamedTuple{" type

Using the read() function from HDF5.jil I obtain this output for data:

43466-element Vector{NamedTuple{(:H1, […]}}:
(H1 = 8.26600, […]),
(H1 = 8.26600, […]),

How can I access a field? e.g. I tried data.H1 and data["H1"] and got
type Array has no field H1 and invalid index: "H1" of type String.

This is working

p = zeros(size(data))

for i in 1:size(data)[1]
   p[i] = data[i].H1
end

but I bet there is a clever way to do it.

I appreciate any help.

p = getproperty.(data, :H1)
4 Likes

Or

p = [x.H1 for x ∈ data]
1 Like

The result you get, a Vector{NamedTuple}, is in the form described as a “row table” in the Tables.jl package. You can convert it to a “column table” and extract the H property as a vector with

julia> using Tables

julia> xvec = columntable(x).H
3 Likes