In these exercises, you will practice operations with factors needed for implementing the analysis of variance (ANOVA) analysis or drawing a boxplot. Also, try applying the function table(X) to some factor X in your R environment – it is the function that quickly counts the number of occurrences of each element in X. These exercises do not count toward your grade. They are just for practice!
Exercises: Modifying factor order
-
There are some suspiciously high numbers in
tvhours
. Is the mean a good summary? -
For each factor in
gss_cat
identify whether the order of the levels is arbitrary or principled. -
Why did moving "Not applicable" to the front of the levels move it to the bottom of the plot?
Exercises: Modifying factor levels
-
How have the proportions of people identifying as Democrat, Republican, and Independent changed over time?
-
How could you collapse
rincome
into a small set of categories?
Source: H. Wickham and G. Grolemund, https://r4ds.had.co.nz/factors.html This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.