What is the difference the zoo object and ts object in R?

xusliebana picture xusliebana · Nov 15, 2015 · Viewed 8.9k times · Source

I want to know the differences into use ts() or zoo() function.

Answer

IRTFM picture IRTFM · Nov 15, 2015

A zoo object has the time values (possibly irregular) in an index attribute displayed like a row name at the console by the print.zoo method and the values in a matrix or atomic vector which places constraints on the values that can be used (generally numeric, but necessarily all of a single mode, i.e. not as a list with multiple modes like a dataframe might hold). With pkg:zoo loaded, to get a list of functions that have zoo-methods:

library(zoo)
methods(class="zoo")

The yrmon- class is added to allow monthly date indices. you can see the range of methods:

methods(class="yearmon")

The xts-class is an important extension to the zoo methods but an additional package is needed. There are many worked examples of zoo and xts functions on SO.

A ts-object has values of a single mode with attributes that always imply regular observations and those attributes support a recurring cycle such as years and months. Rather than storing the index item by item or row by row, the index is calculated on the fly using 'start', 'end' and 'frequency' values stored as attributes and accessible with functions by those names. The list of functions for ts-objects is distinctly small (and most people find them more difficult to work with):

methods(class="ts")

There was also an its-package for irregular time series, but it was distinctly less popular than the zoo-package and has apparently been abandoned.