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.
Cet exercice fait partie du cours
Case Study: Analyzing City Time Series Data in R
Instructions
- View summary information about your
unemploymentdata usingsummary(). Pay close attention to the number ofNA'sidentified in your output. Also note that theminandmaxvalues 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 yourunemploymentobject. - Use
plot.zoo()to plot yourunemploymentdata. Specifyplot.typeas"single"to put both US-wide and Massachusetts-specific data on the same plot. Keep theltyargument and the call tolegend()as they are.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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")