knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This is a vignette that demontrates the use of the 3 main functions of the LPfars
package
fars_read
: Read a single dataset stored on your diskfars_summarize_years
: Summarize the number of observations by yearfars_map_state
: Visualize the accidents in the US mapThrough 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)
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_years
to read multiple FARS data files on your disk
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.