Handle date and time in separate columns
read.zoo() makes it easy to import data when the date and time are in separate columns. The index.column argument allows you to specify the name or number of the column(s) containing the index data. That's all you need to do if the date and time are specified in the standard format ("%Y-%m-%d" for date, and "%H:%M:%S" for time).
In this exercise, you will use the index.column argument to specify the date and time columns of the file. Your working directory has a file named UNE.csv that contains some 5-minute OHLC data for the energy company, Unron. You will still use read.csv() find the column names of the date and time columns.
Cet exercice fait partie du cours
Importing and Managing Financial Data in R
Instructions
- Import the first 5 lines of
UNE.csvusingread.csv(). Assign the output toune_data. - Look at the structure of
une_dataand note the column names and locations. - Use
read.zoo()to importUNE.csv, specifyingindex.columnsas the names of the date and time columns. Assign the output toune_zoo. - Look at the first few rows of
une_zoo.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Read data with read.csv
___ <- read.csv("___", nrows = ___)
# Look at the structure of une_data
# Specify Date and Time index column names
une_zoo <- read.zoo("UNE.csv", index.column = c("___", "___"), sep = "___", header = ___)
# Look at first few rows of data