Practice: Factors

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

  1. There are some suspiciously high numbers in tvhours. Is the mean a good summary?

  2. For each factor in gss_cat identify whether the order of the levels is arbitrary or principled.

  3. Why did moving "Not applicable" to the front of the levels move it to the bottom of the plot?



Exercises:  Modifying factor levels

  1. How have the proportions of people identifying as Democrat, Republican, and Independent changed over time?

  2. How could you collapse rincome into a small set of categories?


Source: H. Wickham and G. Grolemund, https://r4ds.had.co.nz/factors.html
Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 3.0 License.

Last modified: Tuesday, January 3, 2023, 5:01 PM