R/ForestStructure.R

#' A function for calculating mean basal area and stem density across all
#' study sites.
#'
#' @import tidyr dplyr
#' @return ForestStructSumm A tibble containing forest structure summary statistics.
#'
ForestStructure <- function(){
  ForestStruct <- NonSeedlingData %>%
    mutate(BA = BAFormula(.)) %>%
    group_by(Site, Transect, PlotCode) %>%
    summarise(BA = sum(BA)) %>%
    full_join(NonSeedlingData %>%
                count(Site, Transect, PlotCode),
              by = c("Site", "Transect", "PlotCode")) %>%
    right_join(PlotData) %>%
    replace_na(list(BA = 0,
                    n = 0))

  PlotSize <- pi * 4 * 4

  ForestStructSumm <- ForestStruct %>%
    mutate(BAPerHect = BA * (10000 / PlotSize),
           TreesPerHect = n * (10000 / PlotSize)) %>%
    ungroup() %>%
    summarise(MeanBA = mean(BAPerHect),
              SDBA = sd(BAPerHect),
              MeanTrees = mean(TreesPerHect),
              SDTrees = sd(TreesPerHect))
  return(ForestStructSumm)
}
mikemahoney218/BeaverForaging documentation built on May 8, 2019, 7:29 a.m.