Load required libraries...
# #install.packages('readr') # library(readr) # # install.packages('dplyr') # library(dplyr) # # install.packages('stats') # library(stats) # # install.packages('tidyr') # library(tidyr) # # install.packages('graphics') # library(graphics) # # install.packages('maps') # library(maps)
The package includes the FARS dataset files from years 2013 to 2015. To access the raw data files the user can use the following line of code:
system.file("extdata", "accident_2013.csv.bz2", package = "BuildinganRPackageLCP") system.file("extdata", "accident_2014.csv.bz2", package = "BuildinganRPackageLCP") system.file("extdata", "accident_2015.csv.bz2", package = "BuildinganRPackageLCP")
This is the vignette for the R package BuildinganRPackageLCP written in R Markdown as a html_vignette document. The R package BuildinganRPackageLCP implements five useful functions to process and analyze data from the Fatality Analysis Reporting System (FARS). The functions are the following:
The R package BuildinganRPackageLCP has the following main goals:
Manage FRS data file names from user provided year(s).
Extract and summarize FARS data from user provided year(s).
Map FARS data per state and user provided year.
From CRAN
install.packages('BuildinganRPackageLCP')
From GITHUB
devtools::install_github("Darwinita/BuildinganRPackageLCP")
LOAD using
library(BuildinganRPackageLCP)
fars_read(filename)
filename, Is a character string with the name of the input data file.
make_filename(year)
year, A numeric corresponding to the user provided year.
fars_read_years(years)
years, Is a numeric vector containing the series of years for which to extract monthly FARS data.
fars_summarize_years(years)
years, Is a numeric vector containing the series of years for which to summarize FARS data.
fars_map_state(state.num, year)
state.num, Is a numeric corresponding to the user provided state number. year, A numeric corresponding to the user provided year.
#Create a dataframe from data file accident_2015.csv.bz2. library(dplyr) filename <- system.file("extdata", "accident_2015.csv.bz2", package = "BuildinganRPackageLCP") dataframe2015 <- BuildinganRPackageLCP::fars_read(filename) class(dataframe2015) summary(dataframe2015)
#create the filename of FARS accident data for year 2013. BuildinganRPackageLCP::make_filename(2013)
#Extract the monthly FARS data from years 2013, 2014 and 2015. library(dplyr) fars_read_years2013_2015 <- BuildinganRPackageLCP::fars_read_years(c(2013,2014,2015)) class(fars_read_years2013_2015) str(fars_read_years2013_2015)
#Summarize FARS data for years 2013, 2014 and 2015. library(dplyr) library(tidyr) setwd(system.file("extdata", package = "BuildinganRPackageLCP")) DataSummary2013_2015 <- BuildinganRPackageLCP::fars_summarize_years(c(2013,2014,2015)) class(DataSummary2013_2015) str(DataSummary2013_2015) DataSummary2013_2015
#Map FARS data for state nu. 28 in 2015. library(dplyr) library(graphics) library(maps) setwd(system.file("extdata", package = "BuildinganRPackageLCP")) BuildinganRPackageLCP::fars_map_state(28,2015)
Figure 1: FARS data for state number 28 in 2015.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.