Extract one column from one instrument
The quantmod package provides several helper functions to extract specific columns from an object, based on the column name. The Op(), Hi(), Lo(), Cl(), Vo(), and Ad() functions can be used to extract the open, high, low, close, volume, and adjusted close column, respectively.
In this exercise, you will use two of these functions on an xts object named DC. The DC object contains fictitious DataCamp OHLC (open, high, low, close) stock prices created by randomizing some real financial market data. DC is similar to the xts objects created by getSymbols().
While it's not necessary to complete the exercise, you can learn more about all the extractor functions from help("OHLC.Transformations").
Cet exercice fait partie du cours
Importing and Managing Financial Data in R
Instructions
- Use the appropriate extractor function to create an object named
dc_closethat contains only the close column ofDC. - View the first few rows of
dc_close. - Now extract the volume column from
DCand assign it to an object nameddc_volume. - View the first few rows of
dc_volume.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Extract the close column
# Look at the head of dc_close
# Extract the volume column
# Look at the head of dc_volume