-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusing-rfars.Rmd
61 lines (47 loc) · 1.88 KB
/
using-rfars.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: "Introduction to the rfars package"
author: "Cesar R. Urteaga-Reyesvera"
date: "2017-08-03"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Introduction to the rfars package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r Setup, include = FALSE}
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)](https://www.nhtsa.gov/research-data/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.
```{r}
# 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.
```{r}
# 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.
```{r}
# Plots the car fatalities for the state of Florida (12) in 2015.
fars_map_state(12, 2015)
```