#' Hart-Becking index
#'
#' Calculates the Hart-Becking index (%), i.e. the ratio between average spacing and dominant height, expressed in percentage.
#'
#' @param x A data frame with tree records in rows and columns 'ID', 'Species', 'H' (in m) and 'N' (ha-1)
#'
#' @examples
#'
#' data(exampleTreeData)
#'
#' hartBeckingIndex(exampleTreeData)
hartBeckingIndex<-function(x) {
if("ID" %in% names(x)) {
IDs = unique(x$ID)
res = rep(NA, length(IDs))
names(res) = IDs
for(i in 1:length(IDs)) {
h = x$H[x$ID ==IDs[i]]
n = x$N[x$ID ==IDs[i]]
if(length(h)>0 && length(n)>0) res[i] = .hb(h,n)
}
return(res)
}
return(.hb(x$H, x$N))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.