Accessing a column from a vector of vectors

Hi,

I have something like:

a = [["a", "1" ,"11"],
     ["b", "2" ,"22"],
     ["c", "3" ,"33"]]

3-element Vector{Vector{String}}:
 ["a", "1", "11"]
 ["b", "2", "22"]
 ["c", "3", "33"]

And I would like to get e.g. the “a, b, c” or “1, 2, 3” vectors.
Tried various [:,:][…] combos with success.

Are you looking for something more sophisticated than the following?

julia> map(v -> v[1], a)
3-element Vector{String}:
 "a"
 "b"
 "c"
1 Like

Nope, I wondered if the [:,:] kind of syntax would be usable.
Working fine, thanks.

julia> getindex.(a,1)
3-element Vector{String}:
 "a"
 "b"
 "c"

also works

3 Likes

And in the specific case for the a, b, c vector

julia> first.(a)
3-element Vector{String}:
 "a"
 "b"
 "c"

(or last for the last “column”, but getindex more generally as mentioned above)