CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Manipulating Time Series Data in R

Afficher le cours

Instructions

  • Convert date_index_month to the yearmon class and assign it to index_yearmon.

  • Using the values in monthly_data and the index_yearmon index, create a zoo object, monthly_sales.

  • Autoplot monthly_sales with the x-axis label "Month", y-axis label "Sales ($100k)", and title "Corporate Sales Data".

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Create a year-monthly index
___

# Create a zoo object from the year-month index and monthly data
___

# Autoplot with titles and axis labels
___
Modifier et exécuter le code