add as_factor
improve dim