1. Loading data into xts object
Hello! I'm Aric LaBarr and I will 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!
2. xts objects
3. Loading Data Into xts Object
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 structured 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,
4. DataCamp courses about xts
I highly recommend taking these DataCamp courses.
5. Loading Data Example
Remember that an xts object contains two pieces - 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 `seq` function in R. Just specify a starting point, which is typically easier to do with an as dot 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 dot 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 dot hi' in our data set. One nuance you can see here about `xts` objects are that you can call columns by name inside of `xts` objects. For example, your `xts` object called `bev_xts` with a column named `M dot hi` you could call that column specifically as you see here in the slides.
6. Let's practice!
Now you try manipulating data with the xts function!.