Get startedGet started for free

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

View Course

Exercise instructions

  • Fortify the card_prices zoo object into a data frame and assign it to cards_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 the Index and total_price columns of cards_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
___
Edit and Run Code