R/fShannon.R

Defines functions fShannon

Documented in fShannon

fShannon <-
function(x, k, n, location){
  nx <- length(x)
  if (nx==0) stop("No observations)")
  if (k=="") stop("k is missing)")
  if (n=="") stop("n is missing)")
  if (location=="") stop("location is missing)")

  h <- aggregate((-1)*(x[[k]] / x[[n]])*log2(x[[k]] / x[[n]]), by=list(Category=x[[location]]), FUN=sum)
  names(h) <- c("location", "shannon")
  return(h)
}

Try the OnomasticDiversity package in your browser

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

OnomasticDiversity documentation built on May 29, 2024, 1:32 a.m.