dta_freq()
calculates the frequency distribution of a specified
column in a dataframe, with options for sorting, showing missing values,
and customizing the output.
Usage
dta_freq(
dat,
.column,
name = NULL,
is_sorted = FALSE,
is_decreasing = TRUE,
add_percent_symbol = TRUE,
digits = 2
)
Arguments
- dat
A dataframe.
- .column
The column in the dataframe for which the frequency distribution will be calculated.
- name
Optional. A name for the column in the output. Defaults to
NULL
.- is_sorted
Logical. If
TRUE
, sorts the results. Defaults toFALSE
.- is_decreasing
Logical. If
TRUE
, sorts in decreasing order. Defaults toTRUE
.- add_percent_symbol
Logical indicating whether or not to add a % sign to percentages. Default is
TRUE
.- digits
Integer. Number of digits to round the percentage values to. Defaults to
1
.
Examples
# Basic frequency distribution of 'region' column
data("data_sample")
tab <- dta_freq(dat = data_sample, .column = region)
dta_gtable(tab)
# Frequency distribution with sorting in increasing
# order of frequency
tab2 <- dta_freq(
dat = data_sample,
.column = region,
is_sorted = TRUE,
is_decreasing = FALSE
)
dta_gtable(tab2)
# Frequency distribution with sorting in decreasing
# order of frequency
tab3 <- dta_freq(
dat = data_sample,
.column = region,
is_sorted = TRUE,
is_decreasing = TRUE
)
dta_gtable(tab3)
# Remove the percentage symbol
tab3 <- dta_freq(
dat = data_sample,
.column = region,
is_sorted = TRUE,
is_decreasing = TRUE,
add_percent_symbol = FALSE
)
dta_gtable(tab3)