Respect order of input values in unique()

This is more consistent with the documentation of Base.unique().
Only NAs are always put at the end of the levels, for performance
reasons. Fixes the first part of #92.