Learn R Programming

silviculture (version 0.2.0)

silv_stand_qmean_diameter: Calculates the quadratic mean diameter (QMD)

Description

Calculates the quadratic mean diameter (QMD)

Usage

silv_stand_qmean_diameter(diameter, ntrees = NULL)

Value

A numeric vector

Arguments

diameter

Numeric vector of diameters or diameter classes

ntrees

Numeric vector with number of trees of the diameter class per hectare. If ntrees = NULL, the function will assume that each diameter corresponds to only one tree.

Examples

Run this code
## calculate dg for inventory data grouped by plot_id and species
library(dplyr)
inventory_samples |>
mutate(dclass = silv_tree_dclass(diameter)) |>
  summarise(
    height = mean(height, na.rm = TRUE),
    ntrees = n(),
    .by    = c(plot_id, species, dclass)
  ) |>
  mutate(
    ntrees_ha = silv_density_ntrees_ha(ntrees, plot_size = 10),
    h0        = silv_stand_dominant_height(dclass, height, ntrees_ha),
    dg        = silv_stand_qmean_diameter(dclass, ntrees_ha),
    .by       = c(plot_id, species)
  )

## calculate dg for a vector of diameters
silv_stand_qmean_diameter(c(12.5, 23.5, 14, 16, 18.5))

Run the code above in your browser using DataLab