Ordered factors

Since "Male" and "Female" are unordered (or nominal) factor levels, R returns a warning message, telling you that the greater than operator is not meaningful. As seen before, R attaches an equal value to the levels for such factors.

But this is not always the case! Sometimes you will also deal with factors that do have a natural ordering between its categories. If this is the case, we have to make sure that we pass this information to R...

Let us say that you are leading a research team of five data analysts and that you want to evaluate their performance. To do this, you track their speed, evaluate each analyst as "slow", "medium" or "fast", and save the results in speed_vector.

Instruction

As a first step, assign speed_vector a vector with 5 entries, one for each analyst. Each entry should be either "slow", "medium", or "fast". Use the list below:

No need to specify these are factors yet.

# Create speed_vector speed_vector <- # Create speed_vector speed_vector <- c("medium", "slow", "slow", "medium", "fast") test_object("speed_vector", incorrect_msg = "`speed_vector` should be a vector with 5 entries, one for each analyst's speed rating. Don't use capital letters; R is case sensitive!") success_msg("A job well done! Continue to the next exercise.")

Assign to speed_vector a vector containing the character strings "slow", "medium", or "fast".

Previous: 4-6 | Battle of the sexes

Next: 4-8 | Ordered factors (2)

Back to Main