Factors and how to create them
Working with factors
8. Counting observations, part two: forcats style
Modifying factor variables
Summary

Instruction

You know that R sometimes has many ways to get the same result. This is another one of those times. If we use the forcats way, fct_count() will count the occurrence of each level. Instead of the long command we wrote in the previous exercise, all we have to do is type:

fct_count(survey$age)

Exercise

Use fct_count() to calculate the number of people in each marital status group. Use the mrt_status column of the survey dataset.

Stuck? Here's a hint!

Type:

fct_count(survey$mrt_status)