r_factors Flashcards
1
Q
Given the following vector:
- sex_vector <- c(“Male”, “Female”, “Female”, “Male”, “Male”)
Convert “sex_vector” to a factor named “factor_sex_vector”
A
factor_sex_vector <- factor(sex_vector)
2
Q
Given the following vector:
- temperature_vector <- c(“High”, “Low”, “High”,”Low”, “Medium”)
Convert to a factor“factor_temperature_vector” with the following characteristics:
- Levels in order of “Low”, “Medium”, “High”
A
factor_temperature_vector <- factor(temperature_vector, order=TRUE, levels = c(“Low”, “Medium”, “High”) )