Aan de slagGa gratis aan de slag

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").

Deze oefening maakt deel uit van de cursus

Importing and Managing Financial Data in R

Cursus bekijken

Oefeninstructies

  • Use the appropriate extractor function to create an object named dc_close that contains only the close column of DC.
  • View the first few rows of dc_close.
  • Now extract the volume column from DC and assign it to an object named dc_volume.
  • View the first few rows of dc_volume.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Extract the close column


# Look at the head of dc_close


# Extract the volume column


# Look at the head of dc_volume
Code bewerken en uitvoeren