#' Get motorcyclists (old and new db)
#'
#' This finds all motorcyclists (driver or passenger). Does not include parked
#' motorcycles so MC crashes will be lower. Need \strong{OLICTYPE}.
#' @inheritParams get_driver_flags
#' @param vehicle_df vehicle dataframe
#'
#' @return Only motorcyclists in a crash
#' @export
#'
#' @examples
#' \dontrun{get_motorcycle_persons(person17, vehicle17)}
get_motorcycle_persons <- function(person_df, vehicle_df) {
motorcycle <-
vehicle_df |> dplyr::filter(
.data[["VEHTYPE"]] %in% c("Motorcycle", "MOTORCYCLE") |
(
.data[["VEHTYPE"]] == "POLICE ON EMERGENCY" &
.data[["UNITTYPE"]] %in% c("Motorcycle", "MOTORCYCLE")
)
) |> dplyr::select("CRSHNMBR", "UNITNMBR")
motorcycle2 <-
person_df |> dplyr::filter(.data[["VEHTYPE"]] %in% c("AUTOCYCLE", "Autocycle") &
.data[["OLICTYPE"]] == "M") |>
dplyr::select("CRSHNMBR", "UNITNMBR")
both = dplyr::bind_rows(motorcycle, motorcycle2)
return(dplyr::semi_join(
person_df,
both,
by = c("CRSHNMBR", "UNITNMBR")
)) # use semi_join to keep all obsv in x that match in y
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.