ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Importing and Managing Financial Data in R

Ver curso

Instrucciones del ejercicio

  • Import the first 5 lines of UNE.csv using read.csv(). Assign the output to une_data.
  • Look at the structure of une_data and note the column names and locations.
  • Use read.zoo() to import UNE.csv, specifying index.columns as the names of the date and time columns. Assign the output to une_zoo.
  • Look at the first few rows of une_zoo.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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
Editar y ejecutar código