fars_summarize_years: Summarize multiple years of motor vehicle crash data

Description Usage Arguments Value Examples

Description

This function (fars_summarize_years) accepts a vector of years or a single year as input. Motor vehicle crash data for each year in the input vector is read using the fars_read_years function from this package (fars_read_years). The list of dataframes are then merged using the bind_rows function from the dplyr package (bind_rows). The resulting dataframe is grouped by the year and MONTH columns using the group_by function from the dplyr package (group_by). The total number of records relating to each group is then calculated using the summarize function from the dplyr package (summarize). The results are represented with months displayed along the rows and years along the columns by using the spread function from the tidyr package (spread). An error message occurs if the there is no data file for a corresponding input year.

Usage

1

Arguments

years

A string or integer vector giving the years of motor vehicle crash files to read in.

Value

This function returns a data frame containing the number of motor vehicle crashes for each year and month. An error message occurs if the there is no data file for a corresponding input year.

Examples

1
2
3
4
5
6
7
8
## Not run: 
fars_summarize_years(2013)
fars_summarize_years(c(2013, 2014))
fars_summarize_years("2013")
fars_summarize_years(c("2013", "2014"))
fars_summarize_years(years=2013)

## End(Not run)

drsmd23/Fars documentation built on May 15, 2019, 2:54 p.m.