fars_read

library(magrittr)
library(dplyr)
library(maps)
library(graphics)
source('../R/make_filename.R')
source('../R/fars_read_years.R')
source('../R/fars_summerize_years.R')
source('../R/fars_map_state.R')
# source('../data')
# source('../Data/accident_2014.csv.bz2')
# source('../Data/accident_2015.csv.bz2')

The function fars_read() takes as argument the name of a file and reads it into R. if the function does not exist it will return an error: "The file does not exist".

data_2013 <- fars_read('accident_2013.csv.bz2')

One way to use this function is to enter the file name manually. However since we use specific files with generic format "accident_YYYY.csv.bz2". All we need to do is to replace the YYYY with a four digit year. This can be done with the function make_filename() and passing the four-digit year as argument.

filename = make_filename(2013)
print(filename)

Instead of reading files one by one you can use the function fars_read_years() and passing in a vector of years. Then the function will return a list of the table where each element contains the data from a file.

tbl <- fars_read_years(c(2013, 2014, 2015))

Summary Table

the function fars_summerize_years() takes a vector of years and calls fars_read_years() with the vector of years. it does a row binding over all the tbls it groups the yielded tibble by year and MONTH and then counts the occurances and then it makes a wide tibble from the long tibble according to year.

summary_tbl <- fars_summerize_years(c(2013, 2014, 2015))
print(summary_tbl)

fars_map_state

By calling this function you can get the map of accidents in a year and a state in US. You can get this map by inputing a state number and a year.

fars_map_state(10, 2013)


Manemuneee/FarsPack documentation built on May 4, 2019, 1:10 p.m.