#' Dominant height/diameter
#'
#' Calculates dominant height of stands (the average height of the 100 tallest trees) or
#' the dominant diameter of stands dominant height of stands (the average height of the 100 tallest trees)
#'
#' @name dominantHeight
#' @aliases dominantHeight dominantDiameter
#'
#' @param x A data frame with tree records in rows and columns 'ID', 'Species', 'H' (in m), 'DBH' (in cm), and 'N' (ha-1)
#'
#' @examples
#'
#' data(exampleTreeData)
#'
#' dominantHeight(exampleTreeData)
#' dominantDiameter(exampleTreeData)
dominantHeight<-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)) {
res[i] = .domheight(x$H[x$ID ==IDs[i]],x$N[x$ID ==IDs[i]])
}
return(res)
}
return(.domheight(x$H, x$N))
}
#' @rdname dominantHeight
dominantDiameter<-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)) {
res[i] = .domdiameter(x$DBH[x$ID ==IDs[i]],x$N[x$ID ==IDs[i]])
}
return(res)
}
return(.domdiameter(x$DBH, x$N))
}
diameterSD<-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)) {
res[i] = .diameterSD(x$DBH[x$ID ==IDs[i]],x$N[x$ID ==IDs[i]])
}
return(res)
}
return(.diameterSD(x$DBH, x$N))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.