require("knitr") require("dplyr") require("maps") require("graphics") opts_chunk$set(warning=F,message=F)
The FARS Functions package provides several functions for importing and analyzing data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System (FARS).
Briefly, the functions in the FARS functions package are:
fars_read(my_file) - Reads data from a FARS data csv file and returns a data frame tbl object.
make_filename(year) - Makes a filename from a given year
fars_read_years(list_of_years) - Converts a vector of years to a list of filenames and reads data from those files
fars_summarize_years(list_of_years) - Reads data from files and organizes data by year and month
fars_map_state(state,year) - Read data from files and plots accidents in a given state and year on a map.
Typically, one wants to use fars_read_years to read data, fars_summarize_years to read and summarize data, and fars_map_state to read and visualize data.
Read in a few years worth of data.
df <- fars_read_years(c(2013,2014,2015))
We can read and summarize data in one or more years:
df <- fars_summarize_years(2013) print(df)
We can also read and visualize data form a given state in a given year.
fars_map_state(22,2013)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.