fars_summarize_years: Summarize FARS data for multiple years into columns

Description Usage Arguments Details Value Note Examples

Description

This function can be used to get a "tidy" data frame of FARS data for multiple years. Data is summarized by each month of each year with each year in its own column.

Usage

1

Arguments

years

A vector of years

Details

This function processes each element of a vector or list of years as follows: - calls the supporting function, fars_read_years(), to generate a list of MONTH and year, - calls the bind_rows() function from the dplyr package to merge the list elements (MONTH and year) into a single dataframe, - calls the group_by() function from the dplyr package on the dataframe to group them by year and MONTH, - calls the summarize() function from the dplyr package on the grouped data to count the number of occurrences of fatalities for each month within each year, and finally - calls the spread() function from the tidyr package on the summarized data to create a column for each year. - Returns the tidy dataframe to the calling function.

Value

This function returns a dataframe comprising of years (provided as the input parameter) as columns with the fatalities summarized by each month.

Note

Following functions need to be imported: dplyr package: bind_rows(), group_by(), and summarize(). tidyr package: spread. No error handling is performed in this function.

Examples

1
2
3
4
5
6
## Not run: 
fars_summarize_years(c(2014, 2015, 2016))
fars_summarize_years(c(2014:2016))
fars_summarize_years(list(2014, 2015, 2016))

## End(Not run)

masabri01/BuildingRPackagesCoursera documentation built on May 21, 2019, 12:39 p.m.