zoocat: 'zoocat' class

Description Usage Arguments Details Value Examples

View source: R/zoocat.R

Description

A class designed for "zoo" class with a column attribute (cattr) table.

Usage

1
2
zoocat(x = NULL, order.by = index(x), colattr = NULL,
  index.name = "index", ...)

Arguments

x

a matrix. If x is a data frame, it will be converted to a matrix.

order.by

an index vector with unique entries by which the observations in x are ordered.

colattr

the column attributes. Must be a data frame with column names.

index.name

the name of the index variable.

...

other arguments for zoo.

Details

"zoocat" is a S3 class based on the "zoo" class, which means "zoo" with column(C) attributes(AT). It is known that a "zoo" object is a vector or matrix with a index attribute. In a "zoocat" object, another attribute named "cattr" (a data frame with column names) is added to keeps the underlying attribute information of each column. So there are two attributes in a "zoocat" object: "index" and "cattr". The number of rows of the "cattr" table must be the same with ncol(x), where x is the core data. Each row in the "cattr" table is correspondent to each column of the core data matrix.

In summary, "zoocat" class can manage the underlying information of each column more conveniently than only using column names. It can be used to store time series data each column of which is corresponding to several underlying variables.

Two methods can be used to build a "zoocat" object. The first is to use function zoocat, the "cattr" table is specified by argument colattr. The second method is to use cast2zoocat to get the object from a data frame.

When printing "zoocat" objects, column names will be added automatically, but it should be noted that the column names do not exist. As "zoo" object, coredata can be used to extract the core data matrix from the object.

Many methods have been defined for the "zoocat" object. filter_col can be used to get columns which satisfy some conditions. melt can be used to melt the object, like what melt in the reshape2 do. normalize can be used to normalized data using several methods. apply_col can be used to apply a function to each column and bind the results with the "cattr" table. apply_core can apply a function to the whole core data matrix, and bind the results with the "index" or "cattr" table.

It should be noted that all methods for "zoo" objects can be used for "zoocat" objects, such as na.omit, na.approx, na.fill, na.trim, lag. See the help page of zoo.

Value

A "zoocat" object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
x <- matrix(1 : 20, nrow = 5)
colAttr <- data.frame(month = c(2, 3, 5, 6), name = c(rep('xxx', 3), 'yyy'))
zc <- zoocat(x, order.by = 1991 : 1995, colattr = colAttr)
unclass(zc)
zc[1, 3]
zc[2, ]
zc[, '2_xxx']
coredata(zc)
as.matrix(zc)

x <- matrix(1 : 20, nrow = 5)
colAttr <- data.frame(month = c(2, 3, 5, 6), name = c(rep('xxx', 3), 'yyy'))
zc <- zoocat(x, order.by = 1991 : 1995, colattr = colAttr, frequency = 1)

ran-ran/zoocat documentation built on July 5, 2017, 8:41 p.m.