encode_categories function

Encode a given factor variable automatically