knitr::opts_chunk$set(# Collapse output blocks
                      collapse = TRUE, 
                      comment = "#>", 
                      fig.width = 7, 
                      fig.height = 7, 
                      fig.align = "center")
# We set the working directory where the compressed files are stored within the
# package.
WD <- system.file("extdata", package = "rfars")
knitr::opts_knit$set(root.dir = WD)
library(rfars)

This vignette describes what is the rfars package and how it should be used.

Description

The rfars package bundles a set of functions to analyze the data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System (FARS).

Usage

Getting the data into a more manageable format

The function fars_read allows you to extract the data from a compressed format (.bz2) into a tibble object.

# Extracts the data from a compressed file.
library(rfars)
data_2013 <- fars_read("accident_2013.csv.bz2")
head(data_2013)

Summarizing the car fatalities

In order to get the total number of fatalities by month, use the fars_summarize_years function.

# Creates a table by month & year with the total number of fatalities in 2013 y 2014.
fars_summarize_years(c(2013, 2014))

Visualizing the car fatalities by state

The function fars_map_state creates a map with the car fatalities in a US state and a specific year.

# Plots the car fatalities for the state of Florida (12) in 2015. 
fars_map_state(12, 2015)


Cesar-Urteaga/rfars documentation built on May 27, 2019, 7:28 a.m.