R/CodePlots.R

#' Convert plot letter codes to numeric values, for math and graphing.
#'
#' @import dplyr
#' @param x the dataframe to be cleaned
#' @return x$PlotCode the corrected vector
#'
#' @export

CodePlots <- function(x){
  PlotDistances <- list(A = 4,
                        B = 14,
                        C = 24,
                        D = 34,
                        E = 44,
                        F = 54,
                        G = 64)
  x <- x %>%
    mutate(PlotCode = x$Plot)
  for(i in 1:length(PlotDistances)){
    x$PlotCode <- gsub(paste0("\\b", names(PlotDistances)[i], "\\b"), PlotDistances[[i]], x$PlotCode)
  }
  x$PlotCode <- as.numeric(x$PlotCode)
  return(x$PlotCode)
}
mikemahoney218/BeaverForaging documentation built on May 8, 2019, 7:29 a.m.