counts_all is an extension of counts that returns the most or least common unique value(s) for each column vector of a data frame. Also useful for identifying data entry errors or rare cases. For complex use cases see describe_all.

counts_all(data, n = "all", order = c("d", "a", "i"), sep = "_", na.rm = TRUE)

Arguments

data

A data frame (required).

n

The number of unique values you want frequency counts for. Default is "all".

order

"d" for descending/decreasing order. "a" or "i" for ascending/increasing order.

sep

A character string to use to separate unique values from their counts ("_" by default).

na.rm

Should missing values be omitted (TRUE/FALSE)?

Value

A list of character vectors of the unique value frequency counts for each variable of the input data frame sorted in the chosen order. Return values are structured as "value_count", where the "_" portion takes on the value of the sep argument. Returning a character vector makes subsequent manipulation with stringr and other tidyverse tools fairly easily.

See also

Author

Craig P. Hutton, Craig.Hutton@gov.bc.ca

Examples

#using a numeric vector
data <- data(mtcars)

#all unique values of all variables in \code{data} in order of descending frequency
counts_all(data)
#> [[1]]
#> [1] "mtcars_1"
#> 

#the most common values of all variables in \code{data}
counts_all(data, n = 1)
#> [[1]]
#> [1] "mtcars_1"
#> 

#the top 5 most common unique values for all variables in  \code{data}
counts_all(data, n = 5)
#> [[1]]
#> [1] "mtcars_1"
#>