This function compute a two way contingency table and make a flextable with the result.
proc_freq(
x,
row,
col,
main = "",
include.row_percent = TRUE,
include.column_percent = TRUE,
include.table_percent = TRUE,
include.column_total = TRUE,
include.row_total = TRUE,
include.header_row = TRUE,
weight = NULL
)
data.frame
object
characer
column names for row
characer
column names for column
characer
title
boolean
whether to include the row percents; defaults to TRUE
boolean
whether to include the column percents; defaults to TRUE
boolean
whether to include the table percents; defaults to TRUE
boolean
whether to include the row of column totals; defaults to TRUE
boolean
whether to include the column of row totals; defaults to TRUE
boolean
whether to include the header row; defaults to TRUE
character
column name for weight
proc_freq(mtcars, "vs", "gear")
#> a flextable object.
#> col_keys: `vs`, `label`, `3`, `4`, `5`, `Total`
#> header has 2 row(s)
#> body has 10 row(s)
#> original dataset sample:
#> vs label 3 4 5 Total
#> 1 0 Frequency 12.0000000 2.0000000 4.0000000 18.0000
#> 2 0 Row Pct 0.6666667 0.1111111 0.2222222 NA
#> 3 0 Col Pct 0.8000000 0.1666667 0.8000000 NA
#> 4 0 Percent 0.3750000 0.0625000 0.1250000 0.5625
#> 5 1 Frequency 3.0000000 10.0000000 1.0000000 14.0000
proc_freq(mtcars, "gear", "vs")
#> a flextable object.
#> col_keys: `gear`, `label`, `0`, `1`, `Total`
#> header has 2 row(s)
#> body has 14 row(s)
#> original dataset sample:
#> gear label 0 1 Total
#> 1 3 Frequency 12.0000000 3.0000000 15.00000
#> 2 3 Row Pct 0.8000000 0.2000000 NA
#> 3 3 Col Pct 0.6666667 0.2142857 NA
#> 4 3 Percent 0.3750000 0.0937500 0.46875
#> 5 4 Frequency 2.0000000 10.0000000 12.00000
proc_freq(mtcars, "gear", "vs", weight = "wt")
#> a flextable object.
#> col_keys: `gear`, `label`, `0`, `1`, `Total`
#> header has 2 row(s)
#> body has 14 row(s)
#> original dataset sample:
#> gear label 0 1 Total
#> 1 3 Frequency 49.2490000 9.14000000 58.3890000
#> 2 3 Row Pct 0.8434637 0.15653633 NA
#> 3 3 Col Pct 0.7417688 0.25001368 NA
#> 4 3 Percent 0.4783686 0.08877924 0.5671478
#> 5 4 Frequency 5.4950000 25.90500000 31.4000000
proc_freq(mtcars, "gear", "vs", "My title")
#> a flextable object.
#> col_keys: `gear`, `label`, `0`, `1`, `Total`
#> header has 3 row(s)
#> body has 14 row(s)
#> original dataset sample:
#> gear label 0 1 Total
#> 1 3 Frequency 12.0000000 3.0000000 15.00000
#> 2 3 Row Pct 0.8000000 0.2000000 NA
#> 3 3 Col Pct 0.6666667 0.2142857 NA
#> 4 3 Percent 0.3750000 0.0937500 0.46875
#> 5 4 Frequency 2.0000000 10.0000000 12.00000