Generate weighted frequency tables, both for one-way and two-way tables.
wtd.table(
x,
y = NULL,
weights = NULL,
digits = 3,
normwt = FALSE,
useNA = c("no", "ifany", "always"),
na.rm = TRUE,
na.show = FALSE,
exclude = NULL
)
a vector
another optional vector for a two-way frequency table. Must be the same length as x
vector of weights, must be the same length as x
Number of significant digits.
if TRUE, normalize weights so that the total weighted count is the same as the unweighted one
wether to include NA values in the table
(deprecated) if TRUE, remove NA values before computation
(deprecated) if TRUE, show NA count in table output
values to remove from x and y. To exclude NA, use na.rm argument.
If y
is not provided, returns a weighted one-way frequency table
of x
. Otherwise, returns a weighted two-way frequency table of
x
and y
If weights
is not provided, an uniform weghting is used.
If some weights are missing (`NA`), they are converted to zero. In case of missing weights with `normwt=TRUE`, the observations with missing weights are still counted in the unweighted count. You have to filter them out before using this function if you don't want them to be taken into account when using `normwt`.
data(hdv2003)
wtd.table(hdv2003$sexe, weights=hdv2003$poids)
#> Homme Femme
#> 5149382 5921844
wtd.table(hdv2003$sexe, weights=hdv2003$poids, normwt=TRUE)
#> Homme Femme
#> 930.228 1069.772
table(hdv2003$sexe, hdv2003$hard.rock)
#>
#> Non Oui
#> Homme 892 7
#> Femme 1094 7
wtd.table(hdv2003$sexe, hdv2003$hard.rock, weights=hdv2003$poids)
#> Non Oui
#> Homme 5109366.41 40016.02
#> Femme 5872596.42 49247.49