knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(fars)
setwd(system.file("exdata", package = "fars"))

This package provides functionality to interact with the \href{Fatality Analysis Reporting System}{https://www.nhtsa.gov/research-data/fatality-analysis-reporting-system-fars} database. Given a set of .csv.gz datafiles, summaries about the number of accidents per year

Input data

The FARS package needs data files for each year. The files need to be provided in the working directory and named accident_YEAR.csv.bz2. They can be read using the fars_read_years function, which returns a list of accidents counts by month and year.

setwd(system.file("exdata", package = "fars"))
fars_read_years(2013)

Summarizing yearly reports

You can get a report about years by using the function fars_summarize_years.

setwd(system.file("exdata", package = "fars"))
print(dir(getwd()))
fars_summarize_years(c(2013))

Map plots

Finally, you get a plot of all the accidents in a state using the fars_map_state function.

setwd(system.file("exdata", package = "fars"))
fars_map_state(4, 2013)


wesen/coursera_fars documentation built on May 18, 2019, 4:52 p.m.