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

Imputing sales data

You've been asked to create a report that allows management to compare sales figures per quarter for two years. The problem is that the dataset (sales_df) contains missing values. You'll need to impute the values in the year column so that you can visualize the data.

The ggplot2 package has been pre-loaded for you.

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

Reshaping Data with tidyr

ดูคอร์ส

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

  • Inspect sales_df in the console, pay attention to the year column.
  • Use the fill() function to impute the year column in the correct direction.
  • Create a line plot where each year has a different color.

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

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

sales_df %>% 
  # Impute the year column
  ___ %>%
  # Create a line plot with sales per quarter colored by year.
  ggplot(aes(x = ___, y = ___, color = ___, group = year)) +
  geom_line()
แก้ไขและรันโค้ด