julia> using StatsBase
julia> x = ["a", "b", "c", "a", "b", "d"]
6-element Vector{String}:
"a"
"b"
"c"
"a"
"b"
"d"
julia> indicatormat(x)
4ร6 Matrix{Bool}:
1 0 0 1 0 0
0 1 0 0 1 0
0 0 1 0 0 0
0 0 0 0 0 1
but normally I do your option 1
:
julia> df = DataFrame(x=x)
6ร1 DataFrame
Row โ x
โ String
โโโโโโผโโโโโโโโ
1 โ a
2 โ b
3 โ c
4 โ a
5 โ b
6 โ d
julia> select(df, [:x => ByRow(isequal(v))=> Symbol(v) for v in unique(df.x)])
6ร4 DataFrame
Row โ a b c d
โ Bool Bool Bool Bool
โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1 โ true false false false
2 โ false true false false
3 โ false false true false
4 โ true false false false
5 โ false true false false
6 โ false false false true
(DataConvenience.jl is nice
)