1. Learn
  2. /
  3. Courses
  4. /
  5. Reshaping Data with tidyr

Exercise

Big tech stock prices

You're an analyst at an investment firm and want to visualize the weekly closing prices of five big tech firms' stocks. However, the dataset you've been handed (stock_df) is messy and has the year and week variables stored in the column headers. You'll pivot this data into a tidy format, extract the variables from the headers, and create a line plot.

The ggplot2 package has been pre-loaded for you.

Instructions 1/2

undefined XP
    1
    2
  • Pivot stock_df so that the integer columns year and week are created from the column names and the original values are moved to the price column. Use the names_sep argument to separate the column names.