Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include NA data in a table

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?

like image 789
gfa2001 Avatar asked Jul 14 '18 17:07

gfa2001


1 Answers

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
like image 117
coip Avatar answered Oct 10 '22 00:10

coip