If you type levels(factor_survey_vector), you’ll see that it outputs “F” “M”. Watch out: the order with which you assign the levels is important. At that point, you will often want to change the factor levels to “Male” and “Female” instead of “M” and “F” for clarity. Recording the sex with the abbreviations “M” and “F” can be convenient if you are collecting data with pen and paper, but it can introduce confusion when analyzing the data. (You usually need more categories for survey data either way, you use a factor to store the categorical data.) Here, for simplicity, just two categories were recorded, “M” and “F”. A common question for every questionnaire is the sex of the respondent. Levels(factor_vector) <- c("name1", "name2".)Ī good illustration is the raw data that is provided to you by a survey. R allows you to do this with the function levels(): However, sometimes you will want to change the names of these levels for clarity or other reasons. When you first get a data set, you will often notice that it contains factors with specific factor levels.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |