encode_median function

Encode a given factor variable using median encoding