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.
Cet exercice fait partie du cours
Manipulating Time Series Data in R
Instructions
Fortify the
card_priceszooobject into a data frame and assign it tocards_df.Add the three price columns of
cards_dftogether, then assign it to a new column,cards_df$total_price.Make a new time series,
total_price_zoo, from theIndexandtotal_pricecolumns ofcards_df.Autoplot
total_price_zoo.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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
___