R/Find_D84.R

Defines functions Find_D84

Documented in Find_D84

#' A function to find the D84 from a Wolman Pebble count
#'
#' This function outputs the D84 and a csv of linearly interpolated grain sizes
#'
#' @param wolman A dataframe of your Wolman observations.  Column 1 must be named 'lower': it is the lower grain size of classification bin (mm), column 2 must be named 'upper' : it is the upper grain size of classification bin (mm), column 3 must be named 'count' : it is number of observations of this classification. Defaults to NULL
#' @export
#' @return D84 (mm)
#' @return test
#' @return .csv of linearly interpolated grain size distribution in working directory as 'gsd.csv'
#' Find_D84()

Find_D84 = function(wolman) {

  # set up objects for use in the loop
  obvs = as.numeric()
  n.class = nrow(wolman)

  # linearly interpolate between classification points
  for(i in 1:n.class){
    #i = 1
    limits = c(wolman$lower[i], wolman$upper[i])
    points = approx(limits, limits, n = wolman$count[i])
    obvs = c(obvs, points$x)
  }
  obvs = sort(obvs)
  D84 = quantile(obvs, 0.84)
  D84 = as.numeric(D84)
  write.csv(obvs, "gsd.csv", row.names = FALSE)
  return(D84)
}
SGronsdahl/AASHGS documentation built on May 26, 2019, 4:38 p.m.