Calculates the entropy of a category. It uses the amount of categories to scale between 0 and 1.

entropy(x)

Arguments

x

A character or vector with two or more categories

Value

The numeric value of the Shannon entropy scaled between 0 and 1.

Note

It omits the NA if present.

Examples

entropy(c("H", "T", "H", "T"))
#> [1] 1
entropy(c("H", "T", "H", "T", "H", "H", "H"))
#> [1] 0.8631206
entropy(c("H", "T", "H", "T", "H", "H", NA))
#> [1] 0.9182958
entropy(c("H", "T", "H", "T", "H", "H"))
#> [1] 0.9182958
entropy(c("H", "H", "H", "H", "H", "H", NA))
#> [1] 0