Exploring economic data
Now that you've explored weather and flight patterns in Boston, your client has asked you to step back and prepare some economic data. You've gathered some data on the US economy, including gross domestic product (GDP) and unemployment in the US in general and the state of Massachusetts (home to Boston) in particular.
As always, your first step in manipulating time series data should be to convert your data to the xts class. In this exercise, you'll examine and encode time series data on US GDP, which is available in your workspace as gdp
.
This exercise is part of the course
Case Study: Analyzing City Time Series Data in R
Exercise instructions
- View information about your
gdp
data usingsummary()
. What can you conclude from the output of this command? - Begin the process of encoding
gdp
to xts by converting thedate
column to a time object. In this case, it looks like your GDP data are quarterly, so you should use the yearqtr class. - Use
as.xts()
to convertgdp
to an xts object. Remember to index your xts object on thedate
column and remove that column from the xts output using thedata[, 1]
subsetting format. - Use
plot.xts()
to view your GDP data over time. Does anything stand out in your plot?
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Get a summary of your GDP data
# Convert GDP date column to time object
gdp$date <- as.yearqtr(___)
# Convert GDP data to xts
gdp_xts <- as.xts(___[, -1], order.by = ___)
# Plot GDP data over time