Exploring unemployment data
Now that you've reviewed the basic steps for handling missing data, you can more easily examine and clean new time series data on the fly.
In this exercise, you'll gain a bit more practice by exploring, cleaning, and plotting data on unemployment, both in the United States in general and in Massachusetts (MA) in particular. An xts object containing this data, unemployment
is available in your workspace.
This exercise is part of the course
Case Study: Analyzing City Time Series Data in R
Exercise instructions
- View summary information about your
unemployment
data usingsummary()
. Pay close attention to the number ofNA's
identified in your output. Also note that themin
andmax
values of your time index tell you the period covered by your data. - Use
na.approx()
to remove missing values from your unemployment data through linear interpolation. Save these values back into yourunemployment
object. - Use
plot.zoo()
to plot yourunemployment
data. Specifyplot.type
as"single"
to put both US-wide and Massachusetts-specific data on the same plot. Keep thelty
argument and the call tolegend()
as they are.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# View a summary of your unemployment data
# Use na.approx to remove missing values in unemployment data
unemployment <-
# Plot new unemployment data
plot.zoo(___, plot.type = "___", lty = lty)
legend("topright", lty = lty, legend = labels, bg = "white")