16.1 Frequency and contingency table
16.1.1 frq()
and flat_table()
sjmisc
https://strengejacke.github.io/sjmisc/articles/exploringdatasets.html
data(efc)
(efc <- efc %>% as_tibble())
#> # A tibble: 908 x 26
#> c12hour e15relat e16sex e17age e42dep c82cop1 c83cop2 c84cop3 c85cop4 c86cop5
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 16 2 2 83 3 3 2 2 2 1
#> 2 148 2 2 88 3 3 3 3 3 4
#> 3 70 1 2 82 3 2 2 1 4 1
#> 4 168 1 2 67 4 4 1 3 1 1
#> 5 168 2 2 84 4 3 2 1 2 2
#> 6 16 2 2 85 4 2 2 3 3 3
#> # ... with 902 more rows, and 16 more variables: c87cop6 <dbl>, c88cop7 <dbl>,
#> # c89cop8 <dbl>, c90cop9 <dbl>, c160age <dbl>, c161sex <dbl>, c172code <dbl>,
#> # c175empl <dbl>, barthtot <dbl>, neg_c_7 <dbl>, pos_v_4 <dbl>, quol_5 <dbl>,
#> # resttotn <dbl>, tot_sc_e <dbl>, n4pstu <dbl>, nur_pst <dbl>
efc %>%
frq(c161sex)
#>
#> carer's gender (c161sex) <numeric>
#> # total N=908 valid N=901 mean=1.76 sd=0.43
#>
#> Value | Label | N | Raw % | Valid % | Cum. %
#> -----------------------------------------------
#> 1 | Male | 215 | 23.68 | 23.86 | 23.86
#> 2 | Female | 686 | 75.55 | 76.14 | 100.00
#> <NA> | <NA> | 7 | 0.77 | <NA> | <NA>
efc %>%
group_by(e42dep) %>%
frq(c161sex)
#>
#> carer's gender (c161sex) <numeric>
#> # grouped by: independent
#> # total N=66 valid N=66 mean=1.73 sd=0.45
#>
#> Value | Label | N | Raw % | Valid % | Cum. %
#> ----------------------------------------------
#> 1 | Male | 18 | 27.27 | 27.27 | 27.27
#> 2 | Female | 48 | 72.73 | 72.73 | 100.00
#> <NA> | <NA> | 0 | 0.00 | <NA> | <NA>
#>
#>
#> carer's gender (c161sex) <numeric>
#> # grouped by: slightly dependent
#> # total N=225 valid N=224 mean=1.76 sd=0.43
#>
#> Value | Label | N | Raw % | Valid % | Cum. %
#> -----------------------------------------------
#> 1 | Male | 54 | 24.00 | 24.11 | 24.11
#> 2 | Female | 170 | 75.56 | 75.89 | 100.00
#> <NA> | <NA> | 1 | 0.44 | <NA> | <NA>
#>
#>
#> carer's gender (c161sex) <numeric>
#> # grouped by: moderately dependent
#> # total N=306 valid N=306 mean=1.74 sd=0.44
#>
#> Value | Label | N | Raw % | Valid % | Cum. %
#> -----------------------------------------------
#> 1 | Male | 80 | 26.14 | 26.14 | 26.14
#> 2 | Female | 226 | 73.86 | 73.86 | 100.00
#> <NA> | <NA> | 0 | 0.00 | <NA> | <NA>
#>
#>
#> carer's gender (c161sex) <numeric>
#> # grouped by: severely dependent
#> # total N=304 valid N=304 mean=1.79 sd=0.41
#>
#> Value | Label | N | Raw % | Valid % | Cum. %
#> -----------------------------------------------
#> 1 | Male | 63 | 20.72 | 20.72 | 20.72
#> 2 | Female | 241 | 79.28 | 79.28 | 100.00
#> <NA> | <NA> | 0 | 0.00 | <NA> | <NA>
flat_table(efc, e42dep, c161sex)
#> c161sex Male Female
#> e42dep
#> independent 18 48
#> slightly dependent 54 170
#> moderately dependent 80 226
#> severely dependent 63 241