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

This is a vignette that demontrates the use of the 3 main functions of the LPfars package

Read FARS Data

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

NOTE: The LPfars package comes with example raw datasets. The location of the example raw datasets on your disk can be accessed by typing

system.file("extdata", package = "LPfars")

To access the name of a single file, type

system.file("extdata", "the_file_name", package = "LPfars")

library(LPfars)

file <- system.file("extdata", "accident_2013.csv.bz2", package = "LPfars")

data <- fars_read(file)

print(data)

Summary of FARS Data

The fars_summarize_years returns a summary table with the number of monthly accident cases (row) and the defined year(s) (column). Here the input parameter canbe a numeric vector or a list of the year values.

# Set the working directory to the location of the files
# This is for demontrating purposes. Once you have your datasets in your current working directory, you will not have to do this

files_location = system.file("extdata", package = "LPfars")

setwd(files_location)

fars_summarize_years(2013:2015)

NOTE: The function fars_summarise_years calls the function fars_read_yearsto read multiple FARS data files on your disk

Plot the density 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.

files_location = system.file("extdata", package = "LPfars")
setwd(files_location)

# States are recored as integers. Lets have a look at them
unique(data$STATE) 


# Lets pick state # 1 at year 2013

 fars_map_state(1, 2013)


lefkiospaikousis/LPfars documentation built on June 7, 2019, 12:55 a.m.