knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

FARS has been developed in a context of the Coursera's course "Building an R Package". The package provides a few very basic functions, which work on top of embedded in the package sample FARS data (for more information about FARS data please see Fatality Analysis Reporting System).

Usage

Exploring summarized data

It probably makes sense to start analysis FARS data from exprloring the big picture. It is where fars_summarize_years comes into play.

FARS::fars_summarize_years(2013:2015)

Plotting the accidents on a map

You can focus on a specific state and a year and plot the accidents on a map using fars_map_state:

FARS::fars_map_state(6, 2015)

Exploring raw data

The fars_read function will be useful if you want to work with raw data directly. For instanse let's find out the least and the most dangerous hours

## the least and the most dangerous hours

library(knitr)
library(dplyr)

data_file <- FARS::make_filename(2015)
summarized_data <- FARS::fars_read(data_file) %>%
  filter(HOUR != 99) %>%
  group_by(HOUR) %>% 
  summarise(number_of_accidents = n()) %>%
  arrange(number_of_accidents)
d <- rbind(
  head(summarized_data, 1),
  tail(summarized_data, 1))
knitr::kable(d)

cat("\nThe least dangerous hour:", unlist(d[1, "HOUR"]), 
    "\nThe most dangerous hour: ", unlist(d[2, "HOUR"]))


Valentin-Konoshenko/MyFirstRPackage documentation built on May 8, 2019, 6:44 p.m.