Hmisc
Hmisc copied to clipboard
Hmisc::wtd.table inconsistent with base::table for 0-count factor levels
When tabulating factors (with or without weights), I noticed that wtd.table(..., type = "table") is not consistent with table from base R in the presence of factor levels without observations.
x <- factor(c("A", "B"), levels = c("A", "B", "C"))
table(x)
# A B C
# 1 1 0
Hmisc::wtd.table(x, type = "table")
# A B
# 1 1
Unless there is a specific reason for this, I think it would be best to remain consistent with table.