
Create a standard relative frequency table.
prop_table_by_and_all.RdCreate a simple relative frequency table with percentages.
Arguments
- df
A
data.frame.- dep
The name of the dependent variable in the
data.frame.- by_var
The name of the group variable in the
data.frame.- weights
The name of the weights variable in the
data.frame.- na.rm
Set to
FALSEto suppress checking forNAs. IfTRUE,NAsare removed fromxas well as fromweightsprior to variance estimation.- round_perc
With how many decimals should the percentages be given?
Examples
# without weights
prop_table_by_and_all(df = mtcars, dep = "cyl", by_var = "gear")
#> 4 6 8
#> 3 6.7 13.3 80.0
#> 4 66.7 33.3 NA
#> 5 40.0 20.0 40.0
#> Total 34.4 21.9 43.8
# with weights
mtcars2 <- mtcars
mtcars2[, "weights"] <- rep(c(0.5, 1), 16)
prop_table_by_and_all(df = mtcars2, dep = "cyl", by_var = "gear", weights = "weights")
#> 4 6 8
#> 3 4.5 18.2 77.3
#> 4 68.4 31.6 NA
#> 5 42.9 28.6 28.6
#> Total 35.4 25.0 39.6