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

Package funcFARS contains a group of functions that handle the reading, analyszing and plotting of Fatality Analysis Report System (FARS).

library(funcFARS)

Reading the file into R

The data files are arranged by years.

using fars_read function to read in the data for a specific year

The function requires file path as the argument

filename <- make_filename(2015)
filepath <- system.file("extdata", filename, package = "funcFARS")
myfile <- fars_read(filepath)

head(myfile)
using a wrapper function fars_read_years to read data

For reading data of a specific year, one can also directly furnish the year of interest to the function fars_read_years without the need to construct a file name first as for the function fars_read shown above. The function can also read data from several years.The argument in that case is a vector of years.

For the demonstration purpose, we will need set the working directory to where the files are located within the package funcFars. In the acutal usage, you would need to put these files in your working directory.

oldwd <- getwd()
setwd(system.file("extdata", package = "funcFARS"))
fars_read_years(c(2013,2015))
setwd(oldwd)

Summarize the statistic for each year

Function fars_summarize_years summarizes the total number of accidents for each month by year.

oldwd <- getwd()
setwd(system.file("extdata", package = "funcFARS"))
fars_summarize_years(c(2013,2014,2015))

setwd(oldwd)

Plot the locations of accidents by state and year

Function fars_map_state plots the accident location by state and year. The following example shows the location of accidents for Florida in the year of 2015.

oldwd <- getwd()
setwd(system.file("extdata", package = "funcFARS"))
fars_map_state(12,2015)
setwd(oldwd)


jye56/funcFARS documentation built on May 18, 2019, 8:12 p.m.