The fars
package provides various functions to read and summarize data from the Fatality Analysis Reporting System (FARS) at https://www.nhtsa.gov/research-data/fatality-analysis-reporting-system-fars.
fars_read
reads the FARS filename
in csv format and creates a dplyr tbl_df from it. If the file or permission to it does not exist, an error is produced.
library(fars) test_data <- system.file("extdata", "accident_2014.csv.bz2", package = "fars") fars_read(test_data)
make_filename
generates a character string of the FARS filename given the year. The filename follows the format accident_YYYY.csv.bz2
where YYYY is the 4 digit year.
make_filename(2014) make_filename('2014') make_filename(2015-1)
fars_read_years
takes a vector of four digit years (coerced to integer), reads the series of FARS files and returns a dplyr tbl_df of the month and year columns for each file.
fars_read_years(2014)
fars_summarize_years
reads a series of FARS files and returns a frequency table of fatal crashes by month and year.
library(dplyr) fars_summarize_years(2014)
fars_map_state
reads a FARS file and plots a map of fatal crashes.
library(maps) fars_map_state(1,2014) fars_map_state(4,2014)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.