counts {rfars}R Documentation

Generate counts

Description

Use FARS or GES/CRSS data to generate commonly requested counts.

Usage

counts(
  df,
  what = c("crashes", "fatalities", "injuries", "people")[1],
  interval = c("year", "month")[1],
  where = list(states = "all", region = c("all", "ne", "mw", "s", "w")[1], urb = c("all",
    "rural", "urban")[1]),
  who = c("all", "drivers", "passengers", "bicyclists", "pedestrians")[1],
  involved = NULL,
  filterOnly = FALSE
)

Arguments

df

The input data object (must be of class 'FARS' or 'GESCRSS' as is produced by get_fars() and get_gescrss()).

what

What to count: crashes (the default), fatalities, injuries, or people involved.

interval

The interval in which to count: months or years (the default).

where

Where to count. Must be a list with any of the elements: states (can be 'all', full or abbreviated state names, or FIPS codes), region ('all', 'ne', 'mw', 's', or 'w'; short for northeast, midwest, south, and west), urb ('all', 'rural', or 'urban'). Any un-specified elements are set to 'all' by default.

who

The type of person to count: 'all' (default) 'drivers', 'passengers', 'pedestrians', or 'bicyclists'.

involved

Factors involved with the crash. Can be any of: 'distracted driver', 'police pursuit', 'motorcycle', 'pedalcyclist', 'bicyclist', 'pedestrian', 'pedbike', 'young driver', 'older driver', 'speeding', 'alcohol', 'drugs', 'hit and run', 'roadway departure', 'rollover', or 'large trucks'. NULL by default.

filterOnly

Logical, whether to only filter data or reduce to counts (FALSE by default).

Value

Either a filtered tibble (filterOnly=TRUE) or a tibble of counts (filterOnly=FALSE). If filterOnly=TRUE, the tibble that is returned is the 'flat' tibble from the input FARS object, filtered according to other parameters.

If 'df' is a GESCRSS object, the counts returned are the sum of the appropriate weights.

Examples


  ## Not run: 
    counts(get_fars(years = 2019), where = list(states="Virginia", urb="rural"))
  
## End(Not run)

[Package rfars version 1.2.0 Index]