Session Ready
Exercise

Read text file containing multiple instruments

The previous exercises work if each file contains only one instrument. Some software and data vendors may provide data for all instruments in one file. This exercise will teach you how to import a file that contains multiple instruments.

Once again, you can use read.zoo(). This time you will be using its split argument, which allows you to specify the name or number of the columns(s) that contain the variables that identify unique observations.

The two_symbols.csv file in your working directory contains bid/ask data for two instruments, where each row has one bid or ask observation for one instrument. You will use the split argument to import the data into an object that has both bid and ask prices for both instruments on one row.

Instructions
100 XP
  • Import the first 5 lines of two_symbols.csv using read.csv(). Assign the output to two_symbols_data.
  • Look at the structure of two_symbols_data and note the column names and locations.
  • Use read.zoo() to import two_symbols.csv, specifying split as the names of the symbol and type columns. Assign the output to two_symbols_zoo.
  • Look at the first few rows of two_symbols_zoo.