emend_lvl_match function

Match the input factor to supplied levels.