Factors
Using the str()
command, we saw that the region column stores a factor. You can corroborate this by using the class
command on the region column.
The function levels
shows us the categories for the factor.
This exercise is part of the course
Data Science R Basics
Exercise instructions
- For this question we will combine two functions, in a nested way, to determine the number of unique categories.
Use the functions
levels
andlength
to determine the number of regions defined by this dataset and contained inmurders$region
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# We can see the class of the region variable using class
class(murders$region)
# Determine the number of regions included in this variable