Extract multiple columns from one instrument
The quantmod package provides functions to extract a single column, and also has functions to extract specific sets of columns.
Recall OHLC stands for open, high, low, close. Now you can guess which columns the OHLC()
and HLC()
functions extract. There's also an OHLCV()
function, which adds the volume column.
These functions are helpful when you need to pass a set of columns to another function. For example, you might need to pass the high, low, and close columns (in that order) to a technical indicator function.
In this exercise, you will use two of these extractor functions on the same DC
object you used in the last exercise.
This exercise is part of the course
Importing and Managing Financial Data in R
Exercise instructions
- Use one extractor function to create an object named
dc_hlc
that contains the high, low, and close columns ofDC
. - View the first few rows of
dc_hlc
. - Now extract the open, high, low, close, and volume columns from
DC
and assign the result to an object nameddc_ohlcv
. - View the first few rows of
dc_ohlcv
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Extract the high, low, and close columns
# Look at the head of dc_hlc
# Extract the open, high, low, close, and volume columns
# Look at the head of dc_ohlcv