Frequency tables with count()

Frequency tables provide one way of displaying information about your data.

For example, how many male and female penguins are in the sample?

First, use function count() by the variable of interest (sex):

penguins %>%
  count(sex)
## # A tibble: 3 × 2
##   sex        n
##   <fct>  <int>
## 1 female   165
## 2 male     168
## 3 <NA>      11

The penguins dataset includes 165 females, 168 males, and 11 individual birds for which sex is unknown.

To divide these counts by island (as well as sex), count() by island and sex:

penguins %>%
  count(island, sex)
## # A tibble: 9 × 3
##   island    sex        n
##   <fct>     <fct>  <int>
## 1 Biscoe    female    80
## 2 Biscoe    male      83
## 3 Biscoe    <NA>       5
## 4 Dream     female    61
## 5 Dream     male      62
## 6 Dream     <NA>       1
## 7 Torgersen female    24
## 8 Torgersen male      23
## 9 Torgersen <NA>       5

count() is a quick and easy way to produce frequency tables in R.