Skip to contents

Outputs a single character with names and counts of each level of the input factor.

Arguments

x

factor.

max_n

Integer: Return counts for up to this many levels.

return_ordered

Logical: If TRUE, return levels ordered by count, otherwise return in level order.

Value

Character with level counts.

Author

EDG

Examples

# Small number of levels
describe(iris[["Species"]])
#> [1] "setosa: 50; versicolor: 50; virginica: 50"

# Large number of levels: show top n by count
x <- factor(sample(letters, 1000, TRUE))
describe(x)
#> [1] "(Top 5 of 26) r: 54; a: 52; i: 47; m: 45; d: 43"
describe(x, 3)
#> [1] "(Top 3 of 26) r: 54; a: 52; i: 47"
describe(x, 3, return_ordered = FALSE)
#> [1] "(First 3 of 26) a: 52; b: 30; c: 29"