value_counts: Count the frequency of discrete values in a vector

Description Usage Arguments Value

View source: R/counts.R

Description

Calculates the frequency of discrete values in a vector and returns the counts as a tibble. The results can be sorted by value or by count.

Usage

1
2
3
4
5
6
7
value_counts(
  values,
  name = NULL,
  by = "count",
  order = ifelse(by == "value", "asc", "desc"),
  na.rm = FALSE
)

Arguments

values

A vector of values from which frequencies will be calculated.

name

The column name to use for the values column in the results as a string. By default, the variable name of the input vector is used.

by

The column name by which to sort the results as a string. Must be one of either "count" or "value". The default is "count".

order

The order in which to sort the results as a string. Must be one of either "asc" or "desc". The default depends on the value of the by argument. If by is "count" the default order is "desc". If by is "value" the default order is "asc".

na.rm

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

Value

A tibble showing the frequency of each value in the input vector.


olihawkins/cltools documentation built on Sept. 14, 2020, 7:25 a.m.