Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelasq committed Mar 23, 2018
1 parent 0419068 commit d58d30a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 68 deletions.
7 changes: 5 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ devtools::install_github("gvelasq-r/tabr")
## Usage

```{r example, message = FALSE}
# setup (note that tabr automatically imports the magrittr pipe)
# setup (tabr automatically imports the magrittr pipe)
library(tabr)
# one-way table of frequencies
mtcars %>% tab(cyl)
# two-way table of frequencies (a 2x2 contingency table)
# two-way table of frequencies (a special 2x2 contingency table)
mtcars %>% tab(cyl, gear)
# flat contingency tables of three (or more) variables
Expand All @@ -49,6 +49,9 @@ mtcars %>% tab(cyl, gear, am)
# tables wider than the R console are automatically wrapped
mtcars %>% tab(cyl, gear, am, vs)
# missing values are displayed in tidyverse red
tab(letters[24:27])
# ftab() displays only flat contingency tables (here, with two variables)
mtcars %>% ftab(cyl, gear)
Expand Down
143 changes: 77 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ Usage
-----

``` r
# setup (note that tabr automatically imports the magrittr pipe)
# setup (tabr automatically imports the magrittr pipe)
library(tabr)

# one-way table of frequencies
mtcars %>% tab(cyl)
#> cyl │ Freq. Percent Cum.
#> cyl │ Freq. Percent Cum.
#> ────────────┼───────────────────────────────────
#> 4 │ 11 34.4 34.4
#> 6 │ 7 21.9 56.3
#> 8 │ 14 43.8 100.0
#> 4 │ 11 34.4 34.4
#> 6 │ 7 21.9 56.3
#> 8 │ 14 43.8 100.0
#> ────────────┼───────────────────────────────────
#> Total │ 32 100.0  
#> Total │ 32 100.0  

# two-way table of frequencies (a 2x2 contingency table)
# two-way table of frequencies (a special 2x2 contingency table)
mtcars %>% tab(cyl, gear)
#> │ gear │
#> cyl │ 3 4 5 │ Total
Expand All @@ -47,87 +47,98 @@ mtcars %>% tab(cyl, gear)

# flat contingency tables of three (or more) variables
mtcars %>% tab(cyl, gear, am)
#> cyl │ gear am Freq. Percent Cum.
#> cyl │ gear am Freq. Percent Cum.
#> ────────────┼───────────────────────────────────────────────────────────
#> 4 │ 3 0 1 3.1 3.1
#> 4 │ 4 0 2 6.2 9.3
#> 4 │ 4 1 6 18.8 28.1
#> 4 │ 5 1 2 6.2 34.3
#> 4 │ 3 0 1 3.1 3.1
#> 4 │ 4 0 2 6.2 9.3
#> 4 │ 4 1 6 18.8 28.1
#> 4 │ 5 1 2 6.2 34.3
#> ------------┼-----------------------------------------------------------
#> 6 │ 3 0 2 6.2 40.5
#> 6 │ 4 0 2 6.2 46.7
#> 6 │ 4 1 2 6.2 52.9
#> 6 │ 5 1 1 3.1 56.0
#> 6 │ 3 0 2 6.2 40.5
#> 6 │ 4 0 2 6.2 46.7
#> 6 │ 4 1 2 6.2 52.9
#> 6 │ 5 1 1 3.1 56.0
#> ------------┼-----------------------------------------------------------
#> 8 │ 3 0 12 37.5 93.5
#> 8 │ 5 1 2 6.2 99.7
#> 8 │ 3 0 12 37.5 93.5
#> 8 │ 5 1 2 6.2 99.7

# tables wider than the R console are automatically wrapped
mtcars %>% tab(cyl, gear, am, vs)
#> cyl │ gear am vs Freq. Percent
#> 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
#> 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
#> 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
#> 8 │ 3 0 0 12 37.5
#> 8 │ 5 1 0 2 6.2
#>
#> cyl │ Cum.
#> cyl │ Cum.
#> ────────────┼────────────
#> 4 │ 3.1
#> 4 │ 9.3
#> 4 │ 28.1
#> 4 │ 31.2
#> 4 │ 34.3
#> 4 │ 3.1
#> 4 │ 9.3
#> 4 │ 28.1
#> 4 │ 31.2
#> 4 │ 34.3
#> ------------┼------------
#> 6 │ 40.5
#> 6 │ 46.7
#> 6 │ 52.9
#> 6 │ 56.0
#> 6 │ 40.5
#> 6 │ 46.7
#> 6 │ 52.9
#> 6 │ 56.0
#> ------------┼------------
#> 8 │ 93.5
#> 8 │ 99.7
#> 8 │ 93.5
#> 8 │ 99.7

# missing values are displayed in tidyverse 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.
#> 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.3
#> 4 │ 3 1 3.1 3.1
#> 4 │ 4 8 25.0 28.1
#> 4 │ 5 2 6.2 34.3
#> ------------┼-----------------------------------------------
#> 6 │ 3 2 6.2 40.5
#> 6 │ 4 4 12.5 53.0
#> 6 │ 5 1 3.1 56.1
#> 6 │ 3 2 6.2 40.5
#> 6 │ 4 4 12.5 53.0
#> 6 │ 5 1 3.1 56.1
#> ------------┼-----------------------------------------------
#> 8 │ 3 12 37.5 93.6
#> 8 │ 5 2 6.2 99.8
#> 8 │ 3 12 37.5 93.6
#> 8 │ 5 2 6.2 99.8

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

# tab2() displays two-way tables for all variable combinations
mtcars %>% tab2(cyl, gear, am)
Expand Down Expand Up @@ -160,13 +171,13 @@ mtcars %>% tab2(cyl, gear, am)

# ta() is a shortened alias for tab(), inspired by Stata
mtcars %>% ta(gear)
#> gear │ Freq. Percent Cum.
#> gear │ Freq. Percent Cum.
#> ────────────┼───────────────────────────────────
#> 3 │ 15 46.9 46.9
#> 4 │ 12 37.5 84.4
#> 5 │ 5 15.6 100.0
#> 3 │ 15 46.9 46.9
#> 4 │ 12 37.5 84.4
#> 5 │ 5 15.6 100.0
#> ────────────┼───────────────────────────────────
#> Total │ 32 100.0  
#> Total │ 32 100.0  
```

------------------------------------------------------------------------
Expand Down

0 comments on commit d58d30a

Please sign in to comment.