summarise_frequency {tidySummaries}R Documentation

Summarise Frequency Table

Description

Computes the frequency and relative frequency (or percentage) of factor or character variables in a data frame or vector.

Usage

summarise_frequency(
  data,
  select = NULL,
  as_percent = FALSE,
  sort_by = NULL,
  top_n = Inf
)

Arguments

data

A character/factor vector, or a data frame/tibble.

select

Optional. One or more variable names to compute frequencies for. If NULL, all factor/character columns are used.

as_percent

Logical. If TRUE, relative frequencies are returned as percentages (%). Default is FALSE (proportions).

sort_by

Optional. If "N", sorts by frequency; if "group", sorts alphabetically; or "%N" (if as_percent = TRUE). Default is no sorting.

top_n

Integer. Show only the top N values

Value

A tibble with the following columns:

variable

The name of the variable.

group

The group/category values of the variable.

N

The count (frequency) of each group.

%N

The proportion or percentage of each group.

Examples

summarise_frequency(iris, select = "Species")
summarise_frequency(iris, as_percent = TRUE, sort_by = "N", top_n = 2)
summarise_frequency(data.frame(group = c("A", "A", "B", "C", "A")), as_percent = TRUE)


[Package tidySummaries version 0.1.0 Index]