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

Functions

This package includes some useful function to analyze the data in FARS that were

Read FARS Data

Through fars_read, we can read the FARS data that was saved by csv file with ".bz2" extension.

library(fars)
file <- system.file("exdata", "accident_2015.csv.bz2", package = "fars")
data <- fars_read(file)
head(data)

Summary of FARS Data

The fars_summarize_years can return the pivot table with the number of monthly accident cases (row) and the defined year(s) (column). Here the input parameter should be a numeric vector.

setwd(system.file("exdata", package = "fars"))
fars_summarize_years(2013:2015)

Visualization of accident locations

The fars_map_state returns a map with the plot of the state with accident locations. The State index was defined from 1 to 56.

setwd(system.file("exdata", package = "fars"))
unique(data$STATE) # 56
par(mfrow = c(1,3))
for (i in 2013:2015) {
  fars_map_state(50, i)
  mtext(paste(i))
}


nanhung/fars documentation built on May 30, 2019, 4:04 p.m.