เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

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.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Manipulating Time Series Data in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • 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".

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Create a year-monthly index
___

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

# Autoplot with titles and axis labels
___
แก้ไขและรันโค้ด