Learn R Programming

eHDPrep (version 1.3.3)

variable_entropy: Calculate Entropy of Each Variable in Data Frame

Description

Calculates Shannon entropy of all variables in a data frame in bits (default) or natural units. Missing values are omitted from the calculation.

Usage

variable_entropy(data, unit = "bits")

Value

Named numeric vector containing entropy values

Arguments

data

Data Frame to compute on

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
a <- matrix(c(c(1,1,1,1,1,1, 1,2,3,4,5,6)),ncol = 2, dimnames =
list(seq(1,6), c("no_entropy","entropy")))
variable_entropy(as.data.frame(a))

Run the code above in your browser using DataLab