tabit_1 {tabit} | R Documentation |
tabit_1
Description
Function to do frequency tables for single vectors or to do multiple frequency tabulations one for each column.
Usage
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,
...
)
Arguments
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 |
Value
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)
Examples
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