In this chapter you dive into the wonderful world of factors.
The term factor refers to a statistical data type used to store categorical variables. The difference between a categorical variable and a continuous variable is that a categorical variable can belong to a limited number of categories. A continuous variable, on the other hand, can correspond to an infinite number of values.
It is important that R knows whether it is dealing with a continuous or a categorical variable, as the statistical models you will develop in the future treat both types differently. (You will see later why this is the case.)
A good example of a categorical variable is sex. In many circumstances you can limit the sex categories to "Male" or "Female". (Sometimes you may need different categories. For example, you may need to consider chromosomal variation, hermaphroditic animals, or different cultural norms, but you will always have a finite number of categories.)
Assign to variable theory
the value "factors for categorical variables"
.
# Assign to the variable theory what this chapter is about!
# Assign to the variable theory what this chapter is about!
theory <- "factors for categorical variables"
msg_undef <- "It looks like you haven't defined the variable `theory`."
msg_incor <- "The value of `theory` looks incorrect. Make sure to assign it the character string `\"factors for categorical variables\"`. Remember that R is case sensitive."
msg_err <- "Make sure that you defined `theory` correctly, using `<-` for assignment."
# If get error and theory is undefined, point out the error
test_or(test_error(msg_err), test_object("theory", eval = FALSE))
test_object("theory", undefined_msg = msg_undef, incorrect_msg = msg_incor)
success_msg("Good job! Ready to start? Continue to the next exercise!")
Simply assign a variable (<-
); make sure to capitalize correctly.