Skip to contents

ds_auto_freq_table creates multiple one way tables by creating a frequency table for each categorical variable in a data frame. ds_auto_cross_table creates multiple two way tables by creating a cross table for each unique pair of categorical variables in a data frame.

Usage

ds_auto_freq_table(data, ...)

ds_auto_cross_table(data, ...)

Arguments

data

A data.frame or tibble.

...

Column(s) in data.

Details

ds_auto_freq_table is a extension of the ds_freq_table function. It creates a frequency table for each categorical variable in the dataframe. ds_auto_cross_table is a extension of the ds_cross_table function. It creates a two way table for each unique pair of categorical variables in the dataframe.

Deprecated Functions

ds_oway_tables() and ds_tway_tables() have been deprecated. Instead use ds_auto_freq_table() and ds_auto_cross_table().

See also

link{ds_freq_table} link{ds_cross_table}

Examples

# frequency table for all columns
ds_auto_freq_table(mtcarz)
#>                              Variable: cyl                              
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    4          11             11              34.38            34.38    
#> -----------------------------------------------------------------------
#>    6           7             18              21.88            56.25    
#> -----------------------------------------------------------------------
#>    8          14             32              43.75             100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 
#>                              Variable: vs                               
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    0          18             18              56.25            56.25    
#> -----------------------------------------------------------------------
#>    1          14             32              43.75             100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 
#>                              Variable: am                               
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    0          19             19              59.38            59.38    
#> -----------------------------------------------------------------------
#>    1          13             32              40.62             100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 
#>                             Variable: gear                              
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    3          15             15              46.88            46.88    
#> -----------------------------------------------------------------------
#>    4          12             27              37.5             84.38    
#> -----------------------------------------------------------------------
#>    5           5             32              15.62             100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 
#>                             Variable: carb                              
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    1           7              7              21.88            21.88    
#> -----------------------------------------------------------------------
#>    2          10             17              31.25            53.12    
#> -----------------------------------------------------------------------
#>    3           3             20              9.38             62.5     
#> -----------------------------------------------------------------------
#>    4          10             30              31.25            93.75    
#> -----------------------------------------------------------------------
#>    6           1             31              3.12             96.88    
#> -----------------------------------------------------------------------
#>    8           1             32              3.12              100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 

# frequency table for multiple columns
ds_auto_freq_table(mtcarz, cyl, gear)
#>                              Variable: cyl                              
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    4          11             11              34.38            34.38    
#> -----------------------------------------------------------------------
#>    6           7             18              21.88            56.25    
#> -----------------------------------------------------------------------
#>    8          14             32              43.75             100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 
#>                             Variable: gear                              
#> -----------------------------------------------------------------------
#> Levels     Frequency    Cum Frequency       Percent        Cum Percent  
#> -----------------------------------------------------------------------
#>    3          15             15              46.88            46.88    
#> -----------------------------------------------------------------------
#>    4          12             27              37.5             84.38    
#> -----------------------------------------------------------------------
#>    5           5             32              15.62             100     
#> -----------------------------------------------------------------------
#>  Total        32              -             100.00              -      
#> -----------------------------------------------------------------------
#> 

# cross table for all columns
ds_auto_cross_table(mtcarz)
#>     Cell Contents
#>  |---------------|
#>  |     Frequency |
#>  |       Percent |
#>  |       Row Pct |
#>  |       Col Pct |
#>  |---------------|
#> 
#>  Total Observations:  32 
#> 
#>                          cyl vs vs                           
#> -------------------------------------------------------------
#> |              |                     vs                     |
#> -------------------------------------------------------------
#> |          cyl |            0 |            1 |    Row Total |
#> -------------------------------------------------------------
#> |            4 |            1 |           10 |           11 |
#> |              |        0.031 |        0.312 |              |
#> |              |         0.09 |         0.91 |         0.34 |
#> |              |         0.06 |         0.71 |              |
#> -------------------------------------------------------------
#> |            6 |            3 |            4 |            7 |
#> |              |        0.094 |        0.125 |              |
#> |              |         0.43 |         0.57 |         0.22 |
#> |              |         0.17 |         0.29 |              |
#> -------------------------------------------------------------
#> |            8 |           14 |            0 |           14 |
#> |              |        0.438 |            0 |              |
#> |              |            1 |            0 |         0.44 |
#> |              |         0.78 |            0 |              |
#> -------------------------------------------------------------
#> | Column Total |           18 |           14 |           32 |
#> |              |        0.563 |        0.437 |              |
#> -------------------------------------------------------------
#> 
#> 
#>                          cyl vs am                           
#> -------------------------------------------------------------
#> |              |                     am                     |
#> -------------------------------------------------------------
#> |          cyl |            0 |            1 |    Row Total |
#> -------------------------------------------------------------
#> |            4 |            3 |            8 |           11 |
#> |              |        0.094 |         0.25 |              |
#> |              |         0.27 |         0.73 |         0.34 |
#> |              |         0.16 |         0.62 |              |
#> -------------------------------------------------------------
#> |            6 |            4 |            3 |            7 |
#> |              |        0.125 |        0.094 |              |
#> |              |         0.57 |         0.43 |         0.22 |
#> |              |         0.21 |         0.23 |              |
#> -------------------------------------------------------------
#> |            8 |           12 |            2 |           14 |
#> |              |        0.375 |        0.062 |              |
#> |              |         0.86 |         0.14 |         0.44 |
#> |              |         0.63 |         0.15 |              |
#> -------------------------------------------------------------
#> | Column Total |           19 |           13 |           32 |
#> |              |        0.594 |        0.406 |              |
#> -------------------------------------------------------------
#> 
#> 
#>                                 cyl vs gear                                 
#> ----------------------------------------------------------------------------
#> |              |                           gear                            |
#> ----------------------------------------------------------------------------
#> |          cyl |            3 |            4 |            5 |    Row Total |
#> ----------------------------------------------------------------------------
#> |            4 |            1 |            8 |            2 |           11 |
#> |              |        0.031 |         0.25 |        0.062 |              |
#> |              |         0.09 |         0.73 |         0.18 |         0.34 |
#> |              |         0.07 |         0.67 |          0.4 |              |
#> ----------------------------------------------------------------------------
#> |            6 |            2 |            4 |            1 |            7 |
#> |              |        0.062 |        0.125 |        0.031 |              |
#> |              |         0.29 |         0.57 |         0.14 |         0.22 |
#> |              |         0.13 |         0.33 |          0.2 |              |
#> ----------------------------------------------------------------------------
#> |            8 |           12 |            0 |            2 |           14 |
#> |              |        0.375 |            0 |        0.062 |              |
#> |              |         0.86 |            0 |         0.14 |         0.44 |
#> |              |          0.8 |            0 |          0.4 |              |
#> ----------------------------------------------------------------------------
#> | Column Total |           15 |           12 |            5 |           32 |
#> |              |        0.468 |        0.375 |        0.155 |              |
#> ----------------------------------------------------------------------------
#> 
#> 
#>                                                       cyl vs carb                                                        
#> -------------------------------------------------------------------------------------------------------------------------
#> |              |                                                  carb                                                  |
#> -------------------------------------------------------------------------------------------------------------------------
#> |          cyl |            1 |            2 |            3 |            4 |            6 |            8 |    Row Total |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            4 |            5 |            6 |            0 |            0 |            0 |            0 |           11 |
#> |              |        0.156 |        0.188 |            0 |            0 |            0 |            0 |              |
#> |              |         0.45 |         0.55 |            0 |            0 |            0 |            0 |         0.34 |
#> |              |         0.71 |          0.6 |            0 |            0 |            0 |            0 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            6 |            2 |            0 |            0 |            4 |            1 |            0 |            7 |
#> |              |        0.062 |            0 |            0 |        0.125 |        0.031 |            0 |              |
#> |              |         0.29 |            0 |            0 |         0.57 |         0.14 |            0 |         0.22 |
#> |              |         0.29 |            0 |            0 |          0.4 |            1 |            0 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            8 |            0 |            4 |            3 |            6 |            0 |            1 |           14 |
#> |              |            0 |        0.125 |        0.094 |        0.188 |            0 |        0.031 |              |
#> |              |            0 |         0.29 |         0.21 |         0.43 |            0 |         0.07 |         0.44 |
#> |              |            0 |          0.4 |            1 |          0.6 |            0 |            1 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> | Column Total |            7 |           10 |            3 |           10 |            1 |            1 |           32 |
#> |              |        0.218 |        0.313 |        0.094 |        0.313 |        0.031 |        0.031 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> 
#> 
#>                           vs vs am                           
#> -------------------------------------------------------------
#> |              |                     am                     |
#> -------------------------------------------------------------
#> |           vs |            0 |            1 |    Row Total |
#> -------------------------------------------------------------
#> |            0 |           12 |            6 |           18 |
#> |              |        0.375 |        0.188 |              |
#> |              |         0.67 |         0.33 |         0.56 |
#> |              |         0.63 |         0.46 |              |
#> -------------------------------------------------------------
#> |            1 |            7 |            7 |           14 |
#> |              |        0.219 |        0.219 |              |
#> |              |          0.5 |          0.5 |         0.44 |
#> |              |         0.37 |         0.54 |              |
#> -------------------------------------------------------------
#> | Column Total |           19 |           13 |           32 |
#> |              |        0.594 |        0.407 |              |
#> -------------------------------------------------------------
#> 
#> 
#>                                 vs vs gear                                  
#> ----------------------------------------------------------------------------
#> |              |                           gear                            |
#> ----------------------------------------------------------------------------
#> |           vs |            3 |            4 |            5 |    Row Total |
#> ----------------------------------------------------------------------------
#> |            0 |           12 |            2 |            4 |           18 |
#> |              |        0.375 |        0.062 |        0.125 |              |
#> |              |         0.67 |         0.11 |         0.22 |         0.56 |
#> |              |          0.8 |         0.17 |          0.8 |              |
#> ----------------------------------------------------------------------------
#> |            1 |            3 |           10 |            1 |           14 |
#> |              |        0.094 |        0.312 |        0.031 |              |
#> |              |         0.21 |         0.71 |         0.07 |         0.44 |
#> |              |          0.2 |         0.83 |          0.2 |              |
#> ----------------------------------------------------------------------------
#> | Column Total |           15 |           12 |            5 |           32 |
#> |              |        0.469 |        0.374 |        0.156 |              |
#> ----------------------------------------------------------------------------
#> 
#> 
#>                                                        vs vs carb                                                        
#> -------------------------------------------------------------------------------------------------------------------------
#> |              |                                                  carb                                                  |
#> -------------------------------------------------------------------------------------------------------------------------
#> |           vs |            1 |            2 |            3 |            4 |            6 |            8 |    Row Total |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            0 |            0 |            5 |            3 |            8 |            1 |            1 |           18 |
#> |              |            0 |        0.156 |        0.094 |         0.25 |        0.031 |        0.031 |              |
#> |              |            0 |         0.28 |         0.17 |         0.44 |         0.06 |         0.06 |         0.56 |
#> |              |            0 |          0.5 |            1 |          0.8 |            1 |            1 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            1 |            7 |            5 |            0 |            2 |            0 |            0 |           14 |
#> |              |        0.219 |        0.156 |            0 |        0.062 |            0 |            0 |              |
#> |              |          0.5 |         0.36 |            0 |         0.14 |            0 |            0 |         0.44 |
#> |              |            1 |          0.5 |            0 |          0.2 |            0 |            0 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> | Column Total |            7 |           10 |            3 |           10 |            1 |            1 |           32 |
#> |              |        0.219 |        0.312 |        0.094 |        0.312 |        0.031 |        0.031 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> 
#> 
#>                                 am vs gear                                  
#> ----------------------------------------------------------------------------
#> |              |                           gear                            |
#> ----------------------------------------------------------------------------
#> |           am |            3 |            4 |            5 |    Row Total |
#> ----------------------------------------------------------------------------
#> |            0 |           15 |            4 |            0 |           19 |
#> |              |        0.469 |        0.125 |            0 |              |
#> |              |         0.79 |         0.21 |            0 |         0.59 |
#> |              |            1 |         0.33 |            0 |              |
#> ----------------------------------------------------------------------------
#> |            1 |            0 |            8 |            5 |           13 |
#> |              |            0 |         0.25 |        0.156 |              |
#> |              |            0 |         0.62 |         0.38 |         0.41 |
#> |              |            0 |         0.67 |            1 |              |
#> ----------------------------------------------------------------------------
#> | Column Total |           15 |           12 |            5 |           32 |
#> |              |        0.469 |        0.375 |        0.156 |              |
#> ----------------------------------------------------------------------------
#> 
#> 
#>                                                        am vs carb                                                        
#> -------------------------------------------------------------------------------------------------------------------------
#> |              |                                                  carb                                                  |
#> -------------------------------------------------------------------------------------------------------------------------
#> |           am |            1 |            2 |            3 |            4 |            6 |            8 |    Row Total |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            0 |            3 |            6 |            3 |            7 |            0 |            0 |           19 |
#> |              |        0.094 |        0.188 |        0.094 |        0.219 |            0 |            0 |              |
#> |              |         0.16 |         0.32 |         0.16 |         0.37 |            0 |            0 |          0.6 |
#> |              |         0.43 |          0.6 |            1 |          0.7 |            0 |            0 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            1 |            4 |            4 |            0 |            3 |            1 |            1 |           13 |
#> |              |        0.125 |        0.125 |            0 |        0.094 |        0.031 |        0.031 |              |
#> |              |         0.31 |         0.31 |            0 |         0.23 |         0.08 |         0.08 |         0.41 |
#> |              |         0.57 |          0.4 |            0 |          0.3 |            1 |            1 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> | Column Total |            7 |           10 |            3 |           10 |            1 |            1 |           32 |
#> |              |        0.219 |        0.313 |        0.094 |        0.313 |        0.031 |        0.031 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> 
#> 
#>                                                       gear vs carb                                                       
#> -------------------------------------------------------------------------------------------------------------------------
#> |              |                                                  carb                                                  |
#> -------------------------------------------------------------------------------------------------------------------------
#> |         gear |            1 |            2 |            3 |            4 |            6 |            8 |    Row Total |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            3 |            3 |            4 |            3 |            5 |            0 |            0 |           15 |
#> |              |        0.094 |        0.125 |        0.094 |        0.156 |            0 |            0 |              |
#> |              |          0.2 |         0.27 |          0.2 |         0.33 |            0 |            0 |         0.47 |
#> |              |         0.43 |          0.4 |            1 |          0.5 |            0 |            0 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            4 |            4 |            4 |            0 |            4 |            0 |            0 |           12 |
#> |              |        0.125 |        0.125 |            0 |        0.125 |            0 |            0 |              |
#> |              |         0.33 |         0.33 |            0 |         0.33 |            0 |            0 |         0.38 |
#> |              |         0.57 |          0.4 |            0 |          0.4 |            0 |            0 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> |            5 |            0 |            2 |            0 |            1 |            1 |            1 |            5 |
#> |              |            0 |        0.062 |            0 |        0.031 |        0.031 |        0.031 |              |
#> |              |            0 |          0.4 |            0 |          0.2 |          0.2 |          0.2 |         0.16 |
#> |              |            0 |          0.2 |            0 |          0.1 |            1 |            1 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> | Column Total |            7 |           10 |            3 |           10 |            1 |            1 |           32 |
#> |              |        0.219 |        0.312 |        0.094 |        0.312 |        0.031 |        0.031 |              |
#> -------------------------------------------------------------------------------------------------------------------------
#> 
#> 

# cross table for multiple columns
ds_auto_cross_table(mtcarz, cyl, gear, am)
#>     Cell Contents
#>  |---------------|
#>  |     Frequency |
#>  |       Percent |
#>  |       Row Pct |
#>  |       Col Pct |
#>  |---------------|
#> 
#>  Total Observations:  32 
#> 
#>                                 cyl vs gear                                 
#> ----------------------------------------------------------------------------
#> |              |                           gear                            |
#> ----------------------------------------------------------------------------
#> |          cyl |            3 |            4 |            5 |    Row Total |
#> ----------------------------------------------------------------------------
#> |            4 |            1 |            8 |            2 |           11 |
#> |              |        0.031 |         0.25 |        0.062 |              |
#> |              |         0.09 |         0.73 |         0.18 |         0.34 |
#> |              |         0.07 |         0.67 |          0.4 |              |
#> ----------------------------------------------------------------------------
#> |            6 |            2 |            4 |            1 |            7 |
#> |              |        0.062 |        0.125 |        0.031 |              |
#> |              |         0.29 |         0.57 |         0.14 |         0.22 |
#> |              |         0.13 |         0.33 |          0.2 |              |
#> ----------------------------------------------------------------------------
#> |            8 |           12 |            0 |            2 |           14 |
#> |              |        0.375 |            0 |        0.062 |              |
#> |              |         0.86 |            0 |         0.14 |         0.44 |
#> |              |          0.8 |            0 |          0.4 |              |
#> ----------------------------------------------------------------------------
#> | Column Total |           15 |           12 |            5 |           32 |
#> |              |        0.468 |        0.375 |        0.155 |              |
#> ----------------------------------------------------------------------------
#> 
#> 
#>                          cyl vs am                           
#> -------------------------------------------------------------
#> |              |                     am                     |
#> -------------------------------------------------------------
#> |          cyl |            0 |            1 |    Row Total |
#> -------------------------------------------------------------
#> |            4 |            3 |            8 |           11 |
#> |              |        0.094 |         0.25 |              |
#> |              |         0.27 |         0.73 |         0.34 |
#> |              |         0.16 |         0.62 |              |
#> -------------------------------------------------------------
#> |            6 |            4 |            3 |            7 |
#> |              |        0.125 |        0.094 |              |
#> |              |         0.57 |         0.43 |         0.22 |
#> |              |         0.21 |         0.23 |              |
#> -------------------------------------------------------------
#> |            8 |           12 |            2 |           14 |
#> |              |        0.375 |        0.062 |              |
#> |              |         0.86 |         0.14 |         0.44 |
#> |              |         0.63 |         0.15 |              |
#> -------------------------------------------------------------
#> | Column Total |           19 |           13 |           32 |
#> |              |        0.594 |        0.406 |              |
#> -------------------------------------------------------------
#> 
#> 
#>                          gear vs am                          
#> -------------------------------------------------------------
#> |              |                     am                     |
#> -------------------------------------------------------------
#> |         gear |            0 |            1 |    Row Total |
#> -------------------------------------------------------------
#> |            3 |           15 |            0 |           15 |
#> |              |        0.469 |            0 |              |
#> |              |            1 |            0 |         0.47 |
#> |              |         0.79 |            0 |              |
#> -------------------------------------------------------------
#> |            4 |            4 |            8 |           12 |
#> |              |        0.125 |         0.25 |              |
#> |              |         0.33 |         0.67 |         0.38 |
#> |              |         0.21 |         0.62 |              |
#> -------------------------------------------------------------
#> |            5 |            0 |            5 |            5 |
#> |              |            0 |        0.156 |              |
#> |              |            0 |            1 |         0.16 |
#> |              |            0 |         0.38 |              |
#> -------------------------------------------------------------
#> | Column Total |           19 |           13 |           32 |
#> |              |        0.594 |        0.406 |              |
#> -------------------------------------------------------------
#> 
#>