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")
.
This exercise is part of the course
Importing and Managing Financial Data in R
Exercise instructions
- Use the appropriate extractor function to create an object named
dc_close
that contains only the close column ofDC
. - View the first few rows of
dc_close
. - Now extract the volume column from
DC
and assign it to an object nameddc_volume
. - View the first few rows of
dc_volume
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract the close column
# Look at the head of dc_close
# Extract the volume column
# Look at the head of dc_volume