Vectorize(plog2p <- function(p){
return(ifelse(p == 0, 0, p * log2(p)))
}, vectorize.args = "p")
CalculateEntropy <- function(p, normalize.p = FALSE){
if (normalize.p){
p <- p / sum(p)
}
S <- -sum(plog2p(p))
return(S)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.