fars_map_state: Generate a map of a state showing locations of accidents...

Description Usage Arguments Details Value Examples

Description

This function takes in a numbered code for a state and a year as arguments, generates a file name, and reads in data from the file into a data frame.

Usage

1
fars_map_state(state.num, year)

Arguments

state.num

a string or numeric representing the coded value for a state.

year

a string or numeric representing the year for which we want to load accident data.

Details

The function checks to make sure the state number is valid (returns a message "invalid state number" otherwise), and creates a new dataframe consisting only of accidents from that state.

This function will also result in an error if an invalid value for year is given.

If there are no accidents in the state for that year, it returns a message to the user.

The function then checks for longitude values greater than 900 and latitude values greater than 90 and turns them into NAs.

The function then generates the map using longitude and latitude values for the points.

Value

a map of a state showing locations of the accidents for a given year

Examples

1
2
3
4
5
## fars_map_state(05, 2013)

## state <- 05
## year <- 2013
## fars_map_state(state, year)

alphaecho1229/Week4Assessment documentation built on May 12, 2019, 10:30 p.m.