Session Ready
Exercise

Extract the price data

You can use square brackets to extract data from the sbux_df data frame like this sbux_df[rows, columns]. To specify which rows or columns to extract, you have several options:

  • sbux_df[1:5, "Adj.Close"]
  • sbux_df[1:5, 2]
  • sbux_df$Adj.Close[1:5].

These expressions will all extract the first five closing prices. If you do not provide anything for the rows (or columns), all rows (or columns) will be selected (e.g. sbux_df[, "Adj.Close"]). Check this yourself by typing the different options in the console!

Note that in the above operations, the dimension information was lost. To preserve the dimension information, add the drop = FALSE argument.

Instructions
100 XP
  • Assign to the variable closing_prices all the adjusted closing prices while preserving the dimension information.