Get startedGet started for free

Merging time series data by column

1. Merging time series data by column

2. Preparing to merge

Before merging time series data by column, you'll want to ensure that your xts objects have a similar periodicity and cover a comparable time period. To do this, you’ll return to the periodicity() command. In this case, you have daily temperature data from 2007 through 2015 and monthly flight data from 2010 through 2015.

3. Preparing to merge

First, you'll want to subset your temperature data to include only information from 2010 through 2015. Next, you'll want to adjust the periodicity of your daily temperature data to match the monthly flight data from the previous chapter. As you'll see, there are multiple ways to adjust the periodicity of your data, including selecting values to serve as indicators for the whole period or generating an average of all values across the period. Of course, you can only convert to a lower frequency period. For example, from minutes to hours or from days to weeks. To convert in the other direction would require inventing new data from thin air.

4. Using merge() with xts

Once you've adjusted the periodicity, you can merge xts objects by column using the merge() command. The order of the objects listed in your merge() command will determine the order of the columns in your merged object but will not affect the ordering of the rows in time. After you merge your data, you should always examine the new object to make sure the merge was successful.

5. Let's practice!

Let's give it a try!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.