1. Learn
  2. /
  3. Courses
  4. /
  5. Intro to Computational Finance with R

Exercise

Subset directly on dates

The way you selected the data from a specific trading day in the previous exercise was not very convenient, right?

When you create a data frame that has the dates of the stock price as row names, you can select the price on a specific day much more easily. The sample code on the right creates a new data frame sbux_prices_df that has the trading days as row names. You can select the price on 3/1/1994 now simply with sbux_prices_df["3/1/1994", 1].

Instructions

100 XP
  • Assign to price_1 the Starbucks stock price on 3/1/1994.
  • Assign to price_2 the Starbucks stock price on 3/1/1995.