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")

Description

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:

  1. fars_read: A read data file function.
  2. make_filename: A simple function to create the filename of accident data for a given year.
  3. fars_read_years: A function to extraxct monthly data from a given set of years.
  4. fars_summarize_years: A function to summarize FARS events per month and year.
  5. fars_map_state: A function to create a map of FARS events and points plota for a given a state number and year.

Details

The R package BuildinganRPackageLCP has the following main goals:

Installation

From CRAN

install.packages('BuildinganRPackageLCP')

From GITHUB

devtools::install_github("Darwinita/BuildinganRPackageLCP")

LOAD using

library(BuildinganRPackageLCP)

Usage

Usage of fars_read

fars_read(filename)

Arguments

filename, Is a character string with the name of the input data file.

Usage of make_filename

make_filename(year)

Arguments

year, A numeric corresponding to the user provided year.

Usage of fars_read_years

fars_read_years(years)

Arguments

years, Is a numeric vector containing the series of years for which to extract monthly FARS data.

Usage of fars_summarize_years

fars_summarize_years(years)

Arguments

years, Is a numeric vector containing the series of years for which to summarize FARS data.

Usage of fars_map_state

fars_map_state(state.num, year)

Arguments

state.num, Is a numeric corresponding to the user provided state number. year, A numeric corresponding to the user provided year.

Examples

Example 1

#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)

Example 2

#create the filename of FARS accident data for year 2013.
BuildinganRPackageLCP::make_filename(2013)

Example 3

#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)

Example 4

#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

Example 5

#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.



Darwinita/BuildinganRPackageLCP documentation built on May 31, 2019, 1:13 p.m.