Yeah, that’s something that I wanted to do for a long time. Let’s fix it at last: https://github.com/JuliaData/CategoricalArrays.jl/pull/365
Though note that in your example you’ll need levels!(cx, lvls[1], allowmissing=true).
We should probably provide more convenience methods to order levels by frequency and so on, like forcats in R.