R/shannon.R

Defines functions shannon

Documented in shannon

shannon <-function(x){
	#Calculate Shannon's Diversity Index given a list of binomial alleles
	t <- table(x)
	if (length(t)<2) return(NaN)
	P=t[1]/sum(t)
	Q=t[2]/sum(t)
	S=-(P*log(P)+Q*log(Q))
	return(S)
}

Try the msap package in your browser

Any scripts or data that you put into this service are public.

msap documentation built on May 2, 2019, 6:52 p.m.