1. Learn
  2. /
  3. Projects
  4. /
  5. Case Study: Analyzing City Time Series Data in R

Connected

Exercise

Merging using rbind()

Now that you know the structure and scope of your temperature data, your next task will be to convert these objects to xts and merge them using rbind().

Before you can convert an object to xts, you need to identify the column that will form the time index and ensure it is encoded as a time-based object. In this case, you'll want to check the class of the date column in temps_1 and temps_2. Once you identify the appropriate time-based index, you can encode both objects to xts and merge by row.

The temps_1 and temps_2 objects are available in your workspace and the xts package has been loaded for you.

Instructions

100 XP
  • Use two calls to class() to check that the date columns in temps_1 and temps_2 are encoded as time-based objects (Date, POSIXct, POSIXlt, yearmon, etc.).
  • Use as.xts() to encode each of your temperature data frames (temps_1 and temps_2) into a separate xts object. Be sure to specify the relevant time-based column for the order.by argument. Also remember to remove the time-based column using the data[, -column] format.
  • Use two calls to head() to confirm that your new xts objects are properly formatted.
  • Use rbind() on your xts objects to merge them into a single object: temps_xts.
  • Use a combination of first() and last() to identify data from the first 3 days of the last month of the first year in temps_xts.