In this exercise set, we will practice using the forcats factor manipulation package by Hadley Wickham. In the last exercise set, we saw that it is entirely possible to deal with factors in base R, but also that things can get a bit involved and un-intuitive. Forcats simplifies many common factor manipulation tasks and […]
factors
Facing the Facts about Factors: Exercises
Factor variables in R can be mind-boggling. Often, you can just avoid them and use characters vectors instead – just don’t forget to set stringsAsFactors=FALSE. They are, however, very useful in some circumstances, such as statistical modelling and presenting data in graphs and tables. Relying on factors but misunderstanding them has been known to “eat […]
Working With Factors: Exercises
Factor data type in R can be very painful to use, especially for beginners. Fortunately, like everything else, there are packages for working with factors. One of the packages is forcats by RStudio. In this set, you will have an opportunity to exercise it. Answers to the exercises are available here. Please, do all exercises […]
Using factor variables like a pro (Part-2)
In this exercise, we will explore how to define a factor. To learn the fundamentals of how factor variables are constructed, check out the previous exercise here. Answers to the exercises are available here. For other parts in this series, follow the tag factors like a pro. In the last exercise, we learned that the […]
Using factor variables like a pro (Part-1)
In this introduction to factors series, we will approach factors in a somewhat uncommon way. Answers to the exercises are available here. For other parts in this series, follow the tag factors like a pro. This exercise assumes that you have worked with R in some capacity in the past. Specifically, this exercise assumes you […]
Factor exercises
In the exercises below we cover the basics of factors. Before proceeding, first read chapter 4 of An Introduction to R, and the help pages for the cut, and table functions. Answers to the exercises are available here. Exercise 1 If x = c(1, 2, 3, 3, 5, 3, 2, 4, NA), what are the […]