R Tutorial: Loading data into xts object

Eric Labarre shows how to build XTS objects in R for time-series forecasting. He creates a weekly date index starting January 19, 2014, combines it with data using the xts() function, and demonstrates how to pull specific columns by name like "M High" for the Mountain High product.
Chapters
Hello, I'm Eric Labarre and I'll be your instructor for this course on forecasting Product demand. Before we can do anything fancy with modeling, we need to understand how to bring our data into R and make it ready for time series analysis. To do this, we are going to use XTS objects to make the data easier to forecast. We will be making an XTS object out of the data. An XTS object stands for Extensible Time Series. It essentially builds upon ZOO objects which are commonly used for time structure data in R. The easiest way I like to think about XTS objects are essentially a data matrix that is indexed across time. This indexing makes exploration and manipulation of the data extremely easy. If you are interested in learning more granular details about XTS objects, I highly recommend taking these data cam courses. Remember that an XTS object contains two the date index and the data matrix. The data has already been loaded into a matrix for you, but we need to create a date index. Luckily it is rather easy to do just that with the sequence function in R. Just specify a starting point which is typically easier to do with an AS date function, a length of the vector of dates and what unit of time you would like the vector to be in. Here we want 176 weeks starting on January 19, 2014. Creating an XTS object from there is extremely easy. Using the XTS function, just specify your data matrix here called Bev and your date index with the Order by option. Now each of your observations is indexed by a date as you can see here for our Mountain High end product called M High in our data set. One nuance you can see here about XTS objects is that you can call columns by name inside of XTS objects. For example your XTS object called bevxts with a column named M high. You could call that column specifically as you see here in the slides. Now you try manipulating data with the XTS function.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







