counts_tb is a convenience extension of counts that returns the most AND least common "n" unique value(s) a vector. This is useful for identifying data entry errors or rare cases. For complex use cases see describe.

counts_tb(y, n = 10, sep = "_", na.rm = TRUE)

Arguments

y

A vector.

n

The number of top & bottom unique values you want frequency counts for. Default is 10 (fewer than "n" will be shown if there aren't "n" unique values).

sep

This only needs to be modified if some values to be counted contain an underscore, in which case you should change it to a character string that is not present in any of the values of y.

na.rm

Should missing values be omitted (TRUE/FALSE)?

Value

A list of data frames of the top and bottom counts for each variable of the input data frame. Return value columns are "top_v" = top value, "top_n" = count of the top value in the same row of the adjacent top_v column, "bot_v" = bottom value, & "bot_n" = count of the bottom value in the same row of the adjacent bot_v column.

Author

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

Examples

#using the mtcars data
data(mtcars)

counts_tb(mtcars$cyl) #top & bottom values
#>   top_v top_n bot_v bot_n
#> 1     8    14     6     7
#> 2     4    11     4    11
#> 3     6     7     8    14