Get startedGet started for free

Time series object

Many companies gather time-dependent data to look for trends or seasonal variations. As time is irregular, wrangling time-dependent data might be hard, especially in a stressful setting, such as a job interview.

Coercing data to a time series object makes it easier to analyze such datasets.

The xts object takes the following arguments:

  • x - a set of values,
  • order.by - a set of corresponding dates (which need to be of the Date class).

In this exercise, you will work with natural gas prices. The dataset contains two variables:

  • Price - numerical values,
  • Date - dates stored as factors.

The gas dataset is available in your environment.

This exercise is part of the course

Practicing Statistics Interview Questions in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(xts)

# View the structure of gas
str(___)

# Coerce to date class
gas$Date <- ___(gas$Date)
Edit and Run Code