Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

time-series

zoo

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

like image 450
xusliebana Avatar asked Nov 14 '15 23:11

xusliebana


People also ask

What is a zoo object in R?

zoo is an R package providing an S3 class with methods for indexed totally ordered observations, such as discrete irregular time series. Its key design goals are independence of a particular index/time/date class and consistency with base R and the "ts" class for regular time series.

What is XTS zoo in R?

eXtensible Time Series (xts) is a powerful package that provides an extensible time series class, enabling uniform handling of many R time series classes by extending zoo.


1 Answers

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.

like image 61
IRTFM Avatar answered Nov 24 '22 10:11

IRTFM