knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
FarsPackage helps in reading Fatality Analysis Reporting System(FARS) data file and perform some analysis on it. You can easily include this package using following command:
library(farsPackage)
Once package is loaded, you can use following functions to summarize and visualize FARS data.
To load data, you need to copy valid FARS file name into the working directory.
The function system.file
is the key that will allow us to gain access to the 2013 to 2015 data within the package.
### the following code reads access the accident_2013.csv.bz2 file in the folder extdata in package farsPackage and save it as an R object named fars_2013 fars_2013 <- system.file("extdata", "accident_2013.csv.bz2", package = "farsPackage") fars_2014 <- system.file("extdata", "accident_2014.csv.bz2", package = "farsPackage") fars_2015 <- system.file("extdata", "accident_2015.csv.bz2", package = "farsPackage") ### copy the file from its folder and save it to the working directory file.copy(from = fars_2013, to = getwd()) file.copy(from = fars_2014, to = getwd()) file.copy(from = fars_2015, to = getwd())
You can place any valid FARS file data with the provided file name format inside working directory. Then, you can use library functions without any error.
You can use following R command to summarize any FARS file data
summarized_data <- fars_summarize_years(c(2013,2014,2015)) head(summarized_data)
This data represents the number of fatalities occurring in different months of provided years.
To Visualize fatalities data on the basis of different states, you can use following R command:
fars_map_state(state.num = 4, year=2013) fars_map_state(state.num = 4, year=2014) fars_map_state(state.num = 4, year=2015)
After you have analyzed FARS data, you can delete files from working directory using following R commands.
file.remove("./accident_2013.csv.bz2") file.remove("./accident_2014.csv.bz2") file.remove("./accident_2015.csv.bz2")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.