zooreg
is the creator for the S3 class "zooreg"
for regular "zoo"
series. It inherits from "zoo"
and is the analogue to ts
.zooreg(data, start = 1, end = numeric(), frequency = 1,
deltat = 1, ts.eps = getOption("ts.eps"), order.by = NULL)
start
.frequency
or deltat
should be provided.ts.eps
.x
are ordered. If this is specified the arguments start
and
end
are ignored and zoo(data, order.by, frequency)
is
called. See
"zooreg"
which inherits from "zoo"
.
It is essentially a "zoo"
series with a "frequency"
attribute."zooreg"
is a subclass of "zoo"
that is used to represent both weakly
and strictly regular series. Internally, it is the same as "zoo"
except
it also has a "frequency"
attribute. Its index class is more restricted
than "zoo"
. The index: 1. must be numeric or a class which can be coerced
via as.numeric
(such as yearmon
, yearqtr
,
Date
, POSIXct
etc.). 2. when converted to numeric
must be expressable as multiples of 1/frequency. 3.
group generic functions Ops
should be defined, i.e.,
adding/substracting a numeric to/from the index class should produce the correct
value of the index class again.zooreg
is the zoo
analogue to ts
. The arguments
are almost identical, only in the case where order.by
is specified,
zoo
is called with zoo(data, order.by, frequency)
. It
creates a regular series of class "zooreg"
which inherits from "zoo"
.
It is essentially a "zoo"
series with an additional "frequency"
attribute. In the creation of "zooreg"
objects (via zoo
,
zooreg
, or coercion functions) it is always check whether the
index specified complies with the frequency specified.
The class "zooreg"
offers two advantages over code "ts"
: 1. The
index does not have to be plain numeric (although that is the default), it just
must be coercable to numeric, thus printing and plotting can be customized.
2. This class can not only represent strictly regular series, but also series
with an underlying regularity, i.e., where some observations from a regular grid
are omitted.
Hence, "zooreg"
is a bridge between "ts"
and "zoo"
and
can be employed to coerce back and forth between the two classes. The coercion
function as.zoo.ts
returns therefore an object of class "zooreg"
inheriting from "zoo"
. Coercion between "zooreg"
and "zoo"
is also available and drops or tries to add a frequency respectively.
For checking whether a series is strictly regular or does have an underlying
regularity the generic function is.regular
can be used.
Methods to standard generics for regular series such as frequency
,
deltat
and cycle
are available for both "zooreg"
and "zoo"
objects. In the latter case, it is checked first (in a data-driven way)
whether the series is in fact regular or not.
zoo
, is.regular
## equivalent specifications of a quarterly series
## starting in the second quarter of 1959.
zooreg(1:10, frequency = 4, start = c(1959, 2))
as.zoo(ts(1:10, frequency = 4, start = c(1959, 2)))
zoo(1:10, seq(1959.25, 1961.5, by = 0.25), frequency = 4)
## use yearqtr class for indexing the same series
z <- zoo(1:10, yearqtr(seq(1959.25, 1961.5, by = 0.25)), frequency = 4)
z
z[-(3:4)]
## create a regular series with a "Date" index
zooreg(1:5, start = Sys.Date())
## or with "yearmon" index
zooreg(1:5, end = yearmon(2000))
## lag and diff (as it is defined in terms of lag)
## act different on zoo and zooreg objects!
x <- c(1, 4, 5, 6)
zz <- zoo(x, x)
zr <- as.zooreg(zz)
lag(zz)
lag(zr)
diff(zz)
diff(zr)
## standard methods available for regular series
frequency(z)
deltat(z)
cycle(z)
cycle(z[-(3:4)])
Run the code above in your browser using DataLab