Correct syntax error in 'as.factor' statement