--4-Factors
#1-What's a factor and why would you use it?
# Assign to the variable theory what this chapter is about!
theory<-"factors for categorical variables"#2-What's a factor and why would you use it? (2)
# Gender vector
gender_vector <- c("Male", "Female", "Female", "Male", "Male")
# Convert gender_vector to a factor
factor_gender_vector <-factor(gender_vector)
# Print out factor_gender_vectorfactor_gender_vector#3-What's a factor and why would you use it? (3)
# Animals
animals_vector <- c("Elephant", "Giraffe",
"Donkey", "Horse")
factor_animals_vector <- factor(animals_vector)
factor_animals_vector
# Temperature
temperature_vector <- c("High", "Low",
"High","Low", "Medium")
factor_temperature_vector <- factor(temperature_vector,
order = TRUE,
levels = c("Low", "Medium", "High"))
factor_temperature_vector#4-Factor levels
#5-Summarizing a factor
#6-Battle of the sexes
#7-Ordered factors
#8-Ordered factors (2)
#9-Comparing ordered factors
Last updated