#install.packages("remotes") 
#remotes::install_github("forestgeo/allodb")
library(allodb)
data <- read.csv("dbhtestforAGB.xlsx - Sheet1.csv") #I downloaded the class excel sheet so I didn't have to create another dataframe. 
data_clean <- subset(data, !is.na(long) & !is.na(lat)) #Clean up the dataset; remove blank lines.
data_clean$agb <- mapply( #Use mapply to apply the function to the entire matrix; without this, get_biomass was outputting a single numeric value and not a vector. I use this so I can a. use the function more effectively b. run it for all trees that were collected.  
  function(d, g, s, lo, la) {
    get_biomass(
      dbh     = d,
      genus   = g,
      species = s,
      coords  = cbind(lo, la)
    )
  },
  d  = data_clean$dbh,
  g  = data_clean$genus,
  s  = data_clean$species,
  lo = data_clean$long,
  la = data_clean$lat
)

sum(data_clean$agb) #Add up total biomass
## [1] 23377.56
plot(
  x = data_clean$dbh,
  y = data_clean$agb,
  col = factor(data_clean$genus),
  xlab = "DBH (cm)",
  ylab = "AGB (kg)"
) #make a plot