Moving between data.frame and zoo
When working with real-world time series data, you'll often import data from spreadsheets and tabular data – data formatted like a data frame. By converting your data to a zoo
object, you can be better prepared to perform time series analysis!
Likewise, converting a time series into a data frame allows you to manipulate and export your data in a format that's widely readable in other software and programming languages outside of R.
The card_prices
time series – a time series for the mean daily prices of three trading cards – as well as the lubridate
, zoo
, and ggplot2
packages have been loaded for you.
This exercise is part of the course
Manipulating Time Series Data in R
Exercise instructions
Fortify the
card_prices
zoo
object into a data frame and assign it tocards_df
.Add the three price columns of
cards_df
together, then assign it to a new column,cards_df$total_price
.Make a new time series,
total_price_zoo
, from theIndex
andtotal_price
columns ofcards_df
.Autoplot
total_price_zoo
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Fortify to data frame: cards_df
___ <- ___
# Add together the three price columns from cards_df
___ <- ___ + ___ + ___
# Create the total_price_zoo time series
___ <- ___
# Generate an autoplot of the new time series
___