Title: | Simple Tabulation Made Simple |
---|---|
Description: | Simple tabulation should be dead simple. This package is an opinionated approach to easy tabulations while also providing exact numbers and allowing for re-usability. This is achieved by providing tabulations as data.frames with columns for values, optional variable names, frequency counts including and excluding NAs and percentages for counts including and excluding NAs. Also values are automatically sorted by in decreasing order of frequency counts to allow for fast skimming of the most important information. |
Authors: | Peter Meissner [aut, cre] |
Maintainer: | Peter Meissner <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-10-31 05:05:20 UTC |
Source: | https://github.com/petermeissner/tabit |
Function to do frequency tables for single vectors or to do multiple frequency tabulations one for each column.
tabit_1(x, sort = 1, digits = 2, ...) ## S3 method for class 'data.frame' tabit_1(x, sort = 1, digits = 2, ..., as_df = TRUE) ## S3 method for class 'list' tabit_1(x, sort = 1, digits = 2, ..., as_df = TRUE) ## Default S3 method: tabit_1( x, sort = 1, digits = 2, useNA = "always", pct = TRUE, na_to_char = TRUE, ... )
tabit_1(x, sort = 1, digits = 2, ...) ## S3 method for class 'data.frame' tabit_1(x, sort = 1, digits = 2, ..., as_df = TRUE) ## S3 method for class 'list' tabit_1(x, sort = 1, digits = 2, ..., as_df = TRUE) ## Default S3 method: tabit_1( x, sort = 1, digits = 2, useNA = "always", pct = TRUE, na_to_char = TRUE, ... )
x |
the thing to be tabulated |
sort |
should |
digits |
the number of digits to round percentages to |
... |
further optional arguments passed through to methods |
as_df |
if more than one vector has been tabulated at once, should the results be combined into a data.frame before returning |
useNA |
how to handle NAs, defaults to "always" to always include NA as category |
pct |
add percentage columns |
na_to_char |
transform NA values to "NA" character string or not, defaults to TRUE |
Returns a data frame with columns
.variable
(the variable the values stem from),
.value
(the values tabulated by),
.count
(the number of times a value occurred),
.pct
(the percentage that value occurred excluding NAs) and
.pct_incl_na
(the percentage that value occurred including NAs)
tabit_1(mtcars$cyl) ## .variable .value .count .pct pct_incl_na ## 3 . 8 14 43.75 43.75 ## 1 . 4 11 34.38 34.38 ## 2 . 6 7 21.88 21.88 ## 4 . NA 0 NA 0.00 tabit_1(mtcars[, c("cyl", "am")]) ## .variable .value .count .pct .pct_incl_na ## 1 cyl 8 14 43.75 43.75 ## 2 cyl 4 11 34.38 34.38 ## 3 cyl 6 7 21.88 21.88 ## 4 cyl NA 0 NA 0.00 ## 5 am 0 19 59.38 59.38 ## 6 am 1 13 40.62 40.62 ## 7 am NA 0 NA 0.00
tabit_1(mtcars$cyl) ## .variable .value .count .pct pct_incl_na ## 3 . 8 14 43.75 43.75 ## 1 . 4 11 34.38 34.38 ## 2 . 6 7 21.88 21.88 ## 4 . NA 0 NA 0.00 tabit_1(mtcars[, c("cyl", "am")]) ## .variable .value .count .pct .pct_incl_na ## 1 cyl 8 14 43.75 43.75 ## 2 cyl 4 11 34.38 34.38 ## 3 cyl 6 7 21.88 21.88 ## 4 cyl NA 0 NA 0.00 ## 5 am 0 19 59.38 59.38 ## 6 am 1 13 40.62 40.62 ## 7 am NA 0 NA 0.00
Function for cross tabulation of variables within a data.frame or data.frame like.
tabit_x(x, ..., sort = 1, digits = 2, useNA = TRUE) ## S3 method for class 'data.frame' tabit_x(x, ..., sort = 1, digits = 2, useNA = TRUE) ## S3 method for class 'grouped_df' tabit_x(x, ..., sort = 1, digits = 2, useNA = TRUE) ## Default S3 method: tabit_x(x, ..., sort = 1, digits = 2, useNA = "always")
tabit_x(x, ..., sort = 1, digits = 2, useNA = TRUE) ## S3 method for class 'data.frame' tabit_x(x, ..., sort = 1, digits = 2, useNA = TRUE) ## S3 method for class 'grouped_df' tabit_x(x, ..., sort = 1, digits = 2, useNA = TRUE) ## Default S3 method: tabit_x(x, ..., sort = 1, digits = 2, useNA = "always")
x |
the thing to be tabulated |
... |
further optional arguments passed through to methods |
sort |
should |
digits |
the number of digits to round percentages to |
useNA |
whether ro us NAs as value category or not, defaults to TRUE |
The data.frame method will take all column value combination for cross tabulation while the grouped_df method is explicitly for tibbles with group information. For those only value combinations for the group columns are relevant.
Returns a data frame with columns
zero, one or more columns with value combinations to be cross tabulated by,
.count
(the number of times a value occurred),
.pct
(the percentage that value occurred excluding NAs) and
.pct_incl_na
(the percentage that value occurred including NAs)
tabit_x(mtcars) tabit_x(mtcars[, c("cyl", "am")])
tabit_x(mtcars) tabit_x(mtcars[, c("cyl", "am")])
Tabulation function that automatically performs one way tabulations as well as cross tabulations depending on the input type - inheriting from data.frame or not.
ti_tab1(...) tabit(...)
ti_tab1(...) tabit(...)
... |
parameters forwarded to tabit_1/tabit_df |