September 2018
Beginner
206 pages
4h 27m
English
Herein, we will create an ordered factor variable in a dataset. In order to do so, the following steps need to be executed:
Create a vector called gas_price using the following code:
gas_price <- rep(c("low", "medium", "high"), times = 146)gas_price <- gas_price[-1]
It will indicate if gas prices in that area are low, medium, or high on average.
midwest$gas_price <- factor(gas_price, levels = c("low", "medium", "high"), ordered = TRUE)
Verify that the variable has been added to the dataset successfully using table() as follows:
table(midwest$gas_price)
Factor variables are a very important data type in R, since, as we learned previously, ...