datacamp / courses-introduction-to-r

Introduction to R by Jonathan Cornelissen
136 stars 148 forks source link

Levels for factors not clear #30

Open bakera81 opened 7 years ago

bakera81 commented 7 years ago

https://campus.datacamp.com/courses/free-introduction-to-r/chapter-4-factors-4?ex=6

We assign "Female" first when setting the levels: levels(factor_survey_vector) <- c("Female", "Male") but "male" is the first factor: male <- factor_survey_vector[1]

This is because the first element of survey_vector is "M" Could this behavior be made clearer somehow?

ramnathv commented 6 years ago

It would be better to make this explicit by using

levels(x) <- c(F = "Female", M = "Male")