R/segment_veh.R

Defines functions segment_veh

Documented in segment_veh

#' Segment Vehicles
#'
#' This function attempts to segment vehicles based on the decision tree in Davison 2020.
#'
#' @param area The frontal surface area of the vehicle in metres squared.
#' @param mass The kerb weight of the vehicle in tonnes.
#' @param type The type approval category of the vehicle - currently either "M1" or "N1".
#' @return A modelled vehicle segment.
#' @export

segment_veh = function(area, mass, type){

  segment = dplyr::case_when(
    !type %in% c("M1","N1")                                  ~ NA_character_,
    area >= 3 & type == "M1"                                 ~ "J",
    area >= 3 & type == "N1" & mass >= 1.760                 ~ "V3",
    area >= 3 & type == "N1" & mass >= 1.305 & mass < 1.760  ~ "V2",
    area >= 3 & type == "N1" & mass < 1.305                  ~ "V1",
    area < 3 & mass < 0.95                                   ~ "A",
    area < 3 & mass >= 0.95 & mass < 1.3                     ~ "B",
    area < 3 & mass >= 1.3 & area < 2.7                      ~ "C",
    area < 3 & mass >= 1.3 & area >= 2.7                     ~ "D")

  return(segment)

}
jack-davison/jdavisonmisc documentation built on Jan. 1, 2021, 4:26 a.m.