我想改变向量的级数,但我不知道如何在julia中做到这一点。
我的julia版本是1.1,我的代码是:
Sire = ["ZA","AD","BB","AD","AD","CC","CC","AD","AD"]
levels(Sire)
levels(Sire) = [1,2,3,4]错误消息:
julia> levels(Sire) = [1,2,3,4]
ERROR: error in method definition: function Missings.levels must be explicitly imported to be extended
Stacktrace:
[1] top-level scope at none:0发布于 2019-08-13 10:00:39
我做一个总结:
Sire = ["ZA","AD","BB","AD","AD","CC","CC","AD","AD"]
# methods 1
a1 = deepcopy(Sire)
new = collect(1:length(levels(Sire)))
d = Dict(zip(levels(a1),new))
using CategoricalArrays
re1 = recode(a1,d...)
# methods 2
a2 = deepcopy(Sire)
new = collect(1:length(levels(Sire)))
un = unique(a2)
replace(a2, Pair.(un, axes(un, 1))...)
# methods 3
a3 = deepcopy(Sire)
new = collect(1:length(levels(a3)))
d = Dict(zip(levels(a3),new))
re3 = replace(a3,d...)https://stackoverflow.com/questions/57457123
复制相似问题