#' Get numeric averages for the DBHClass column in the InventoryData dataset
#'
#' @param x the InventoryData dataframe
#' @return a vector of transformed values
#'
#' @import dplyr
DiameterAverage <- function(x){
DBHAvgs <- list(
"0-1" = 0.5,
"1-2" = 1.5,
"2-5" = 3.5,
"5-10" = 7.5,
"15+" = 15,
"10-15" = 12.5,
"15+" = 15
)
x <- x %>%
mutate(DBHAvg = x$DBHClass)
for(i in 1:length(DBHAvgs)){
x$DBHAvg <- gsub(paste0("\\b", names(DBHAvgs)[i], "\\b"), DBHAvgs[[i]], x$DBHAvg)
}
x$DBHAvg <- as.numeric(x$DBHAvg)
return(x$DBHAvg)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.