Practical guides ↗

R · Statistical analysis

Count categories including missing values

See category counts and NA values together.

3 min readScope: Base R

Try it in three steps

  1. Create an example vector: x <- c("bus", "walk", "bus", NA).
  2. Run table(x, useNA="ifany").
  3. Compare category counts and NA counts with the number of observations.

How to read the output

Expected counts: bus=2, walk=1, NA=1; four observations overall.

Test your understanding.

True or false?

For c("bus", "walk", "bus", NA), a table including missing values has a bus count of 2.

Related concepts

Official source

R · Documentation ↗

Documentation checked: . Steps are based on official documentation and have not been tested in the application. Menu names may differ by version and interface language.