as_factor function

Convert labelled vectors to factors while preserving attributes