This has exactly the effect that I want. However, I would like to issue this command using two vectors x=[1;2;3] and y=[“USA”,“MEX”,“CAN”] in order to make it more flexible, so I don’t have to change the code when these vectors change. Is there a way to do this?
You might want to look at CategoricalArrays.jl, and the recode!() function. I think that interface is really nice and intuitive, and designed for exactly this kind of situation.
Another approach that doesn’t use another package would be to use a dictionary.
d = Dict(k => v for (k, v) in zip(1:3, ("USA", "MEX", "CAN")))
a1.label = [d[n] for n in a1.A]