zoo::yearmon
When processing time series data that's based on the month and quarter of a year, it's often necessary to use the yearmon and yearqtr classes from the zoo package. By doing so, you can have data where the specific date of an observation is unknown or is unnecessary.
In this exercise, you'll work with a vector of sales data, monthly_data, and an index of dates of observations, date_index_month, with each observation occurring on the first of the month.
The above datasets, as well as the ggplot2, zoo, and lubridate packages are available to you.
This exercise is part of the course
Manipulating Time Series Data in R
Exercise instructions
Convert
date_index_monthto theyearmonclass and assign it toindex_yearmon.Using the values in
monthly_dataand theindex_yearmonindex, create azooobject,monthly_sales.Autoplot
monthly_saleswith the x-axis label"Month", y-axis label"Sales ($100k)", and title"Corporate Sales Data".
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a year-monthly index
___
# Create a zoo object from the year-month index and monthly data
___
# Autoplot with titles and axis labels
___