Learn R Programming

eHDPrep (version 1.3.3)

entropy: Calculate Entropy of a Vector

Description

Calculates Shannon Entropy of a vector in bits (default) or natural units. Missing values are omitted from the calculation.

Usage

entropy(x, unit = c("bits"))

Value

Entropy of input variable

Arguments

x

Input vector

unit

Unit to measure entropy. Either "bits" (default) or "nats".

References

Shannon, C. E. A mathematical theory of communication. The Bell System Technical Journal 27, 379–423 (1948).

Examples

Run this code
# no entropy:
vec <- c(1,1,1,1,1,1)
entropy(vec)

# entropy
vec <- c(1,2,3,4,5,6)
entropy(vec)

Run the code above in your browser using DataLab