Function convertToFactor