How to include NA data in a table

gfa2001 picture gfa2001 · Jul 14, 2018 · Viewed 7.1k times · Source

I've recently been using the package tab in R to build frequency tables. Using the tabfreq() or the tabmulti() functions, the default output excludes NA values. Does anyone know the command to include NA values within these functions?

Answer

coip picture coip · Mar 29, 2019

The table() function in base R can display missing values (i.e. NAs) via useNA, which takes several arguments: "no", "ifany", or "always".

data(airquality) # loads the built-in data frame, which has NAs
table(airquality$Ozone, useNA = "always") # always displays the number of missing values
table(airquality$Wind, useNA = "ifany") # only displays the number of missing values if there are some