Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create tidyverse-friendly tables of frequencies

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

gvelasq/tidytab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

tidytab

Create tidyverse-friendly tables of frequencies

R-CMD-check Codecov test coverage CRAN status R-universe status Lifecycle: experimental

Installation

You can install tidytab from GitHub with:

# install.packages("devtools")
devtools::install_github("gvelasq/tidytab")

Usage

library(tidytab)

# one-way table of frequencies
mtcars |> tab(cyl)
#>         cyl β”‚      Freq.     Percent        Cum. 
#> ────────────┼───────────────────────────────────
#>           4 β”‚         11        34.4        34.4 
#>           6 β”‚          7        21.9        56.2 
#>           8 β”‚         14        43.8       100.0 
#> ────────────┼───────────────────────────────────
#>       Total β”‚         32       100.0          Β 

# two-way table of frequencies (a special 2x2 contingency table)
mtcars |> tab(cyl, gear)
#>            β”‚      gear                       β”‚           
#>        cyl β”‚         3          4          5 β”‚     Total 
#> ───────────┼─────────────────────────────────┼──────────
#>          4 β”‚         1          8          2 β”‚        11 
#>          6 β”‚         2          4          1 β”‚         7 
#>          8 β”‚        12          0          2 β”‚        14 
#> ───────────┼─────────────────────────────────┼──────────
#>      Total β”‚        15         12          5 β”‚        32

# flat contingency tables of three (or more) variables
mtcars |> tab(cyl, gear, am)
#>         cyl β”‚       gear          am       Freq.     Percent        Cum. 
#> ────────────┼───────────────────────────────────────────────────────────
#>           4 β”‚          3           0           1         3.1         3.1 
#>           4 β”‚          4           0           2         6.2         9.4 
#>           4 β”‚          4           1           6        18.8        28.1 
#>           4 β”‚          5           1           2         6.2        34.4 
#> ------------β”Ό-----------------------------------------------------------
#>           6 β”‚          3           0           2         6.2        40.6 
#>           6 β”‚          4           0           2         6.2        46.9 
#>           6 β”‚          4           1           2         6.2        53.1 
#>           6 β”‚          5           1           1         3.1        56.2 
#> ------------β”Ό-----------------------------------------------------------
#>           8 β”‚          3           0          12        37.5        93.8 
#>           8 β”‚          5           1           2         6.2       100.0

# tables wider than the R console are automatically wrapped
mtcars |> tab(cyl, gear, am, vs)
#>         cyl β”‚       gear          am          vs       Freq.     Percent
#> ────────────┼───────────────────────────────────────────────────────────
#>           4 β”‚          3           0           1           1         3.1
#>           4 β”‚          4           0           1           2         6.2
#>           4 β”‚          4           1           1           6        18.8
#>           4 β”‚          5           1           0           1         3.1
#>           4 β”‚          5           1           1           1         3.1
#> ------------β”Ό-----------------------------------------------------------
#>           6 β”‚          3           0           1           2         6.2
#>           6 β”‚          4           0           1           2         6.2
#>           6 β”‚          4           1           0           2         6.2
#>           6 β”‚          5           1           0           1         3.1
#> ------------β”Ό-----------------------------------------------------------
#>           8 β”‚          3           0           0          12        37.5
#>           8 β”‚          5           1           0           2         6.2
#> 
#>         cyl β”‚        Cum.
#> ────────────┼────────────
#>           4 β”‚         3.1
#>           4 β”‚         9.4
#>           4 β”‚        28.1
#>           4 β”‚        31.2
#>           4 β”‚        34.4
#> ------------β”Ό------------
#>           6 β”‚        40.6
#>           6 β”‚        46.9
#>           6 β”‚        53.1
#>           6 β”‚        56.2
#> ------------β”Ό------------
#>           8 β”‚        93.8
#>           8 β”‚       100.0

# missing values are displayed in red
tab(letters[24:27])
#>   letters[24:27] β”‚      Freq.     Percent        Cum. 
#> ─────────────────┼───────────────────────────────────
#>                x β”‚          1        25.0        25.0 
#>                y β”‚          1        25.0        50.0 
#>                z β”‚          1        25.0        75.0 
#>               NA β”‚          1        25.0       100.0 
#> ─────────────────┼───────────────────────────────────
#>            Total β”‚          4       100.0          Β 

# ftab() displays only flat contingency tables (here, with two variables)
mtcars |> ftab(cyl, gear)
#>         cyl β”‚       gear       Freq.     Percent        Cum. 
#> ────────────┼───────────────────────────────────────────────
#>           4 β”‚          3           1         3.1         3.1 
#>           4 β”‚          4           8        25.0        28.1 
#>           4 β”‚          5           2         6.2        34.4 
#> ------------β”Ό-----------------------------------------------
#>           6 β”‚          3           2         6.2        40.6 
#>           6 β”‚          4           4        12.5        53.1 
#>           6 β”‚          5           1         3.1        56.2 
#> ------------β”Ό-----------------------------------------------
#>           8 β”‚          3          12        37.5        93.8 
#>           8 β”‚          5           2         6.2       100.0

# tab1() displays one-way tables for each variable
mtcars |> tab1(cyl, gear)
#>         cyl β”‚      Freq.     Percent        Cum. 
#> ────────────┼───────────────────────────────────
#>           4 β”‚         11        34.4        34.4 
#>           6 β”‚          7        21.9        56.2 
#>           8 β”‚         14        43.8       100.0 
#> ────────────┼───────────────────────────────────
#>       Total β”‚         32       100.0          Β  
#> 
#>        gear β”‚      Freq.     Percent        Cum. 
#> ────────────┼───────────────────────────────────
#>           3 β”‚         15        46.9        46.9 
#>           4 β”‚         12        37.5        84.4 
#>           5 β”‚          5        15.6       100.0 
#> ────────────┼───────────────────────────────────
#>       Total β”‚         32       100.0          Β 

# tab2() displays two-way tables for all variable combinations
mtcars |> tab2(cyl, gear, am)
#>            β”‚      gear                       β”‚           
#>        cyl β”‚         3          4          5 β”‚     Total 
#> ───────────┼─────────────────────────────────┼──────────
#>          4 β”‚         1          8          2 β”‚        11 
#>          6 β”‚         2          4          1 β”‚         7 
#>          8 β”‚        12          0          2 β”‚        14 
#> ───────────┼─────────────────────────────────┼──────────
#>      Total β”‚        15         12          5 β”‚        32 
#> 
#>            β”‚        am            β”‚           
#>        cyl β”‚         0          1 β”‚     Total 
#> ───────────┼──────────────────────┼──────────
#>          4 β”‚         3          8 β”‚        11 
#>          6 β”‚         4          3 β”‚         7 
#>          8 β”‚        12          2 β”‚        14 
#> ───────────┼──────────────────────┼──────────
#>      Total β”‚        19         13 β”‚        32 
#> 
#>            β”‚        am            β”‚           
#>       gear β”‚         0          1 β”‚     Total 
#> ───────────┼──────────────────────┼──────────
#>          3 β”‚        15          0 β”‚        15 
#>          4 β”‚         4          8 β”‚        12 
#>          5 β”‚         0          5 β”‚         5 
#> ───────────┼──────────────────────┼──────────
#>      Total β”‚        19         13 β”‚        32

Code of Conduct

Please note that the tidytab project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Contributors

All contributions to this project are gratefully acknowledged using the allcontributors package following the all-contributors specification. Contributions of any kind are welcome!

Code


gvelasq

askawron

ramongss

Issue Authors


fkohrt

zhizhongpu

theshiniss

Issue Contributors


lhdjung

About

Create tidyverse-friendly tables of frequencies

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •  

Languages