cat_count {tabbycat}R Documentation

Count the frequency of discrete values in the column of a dataframe

Description

This function differs from cat_vcount in that it operates on columns in dataframes rather than directly on vectors, which means it is more useful in pipelines but handles a narrower range of inputs. The results are sorted in descending order of frequency.

Usage

cat_count(
  data,
  cat,
  na.rm = FALSE,
  only = "",
  clean_names = getOption("tabbycat.clean_names")
)

Arguments

data

A dataframe containing a categorical vector for which frequencies will be calculated.

cat

The column name of the categorical variable for which frequencies will be calculated.

na.rm

A boolean indicating whether to exclude NAs from the results. The default is FALSE.

only

A string indicating that only one of the frequency columns should be returned in the results. If only is either "n" or "number", only the number column is returned. If only is either "p" or "percent", only the percent column is returned. If only is any other value, both columns are shown. The default value is an empty string, which means both columns are shown.

clean_names

A boolean indicating whether the column names of the results tibble should be cleaned, so that any column names produced from data are converted to snake_case. The default is TRUE, but this can be changed with options(tabbycat.clean_names = FALSE).

Value

A tibble showing the frequency of each value in cat.


[Package tabbycat version 0.18.0 Index]