Description Usage Arguments Details Value Examples
Apply a function over the core data matrix of the "zoocat" object,
and bind the returned data with cattr or index.
1 2 3 4 | apply_core(x, ...)
## S3 method for class 'zoocat'
apply_core(x, FUN, bind = NULL, ...)
|
x |
the object. |
... |
other arguments for |
FUN |
the function to apply. The |
bind |
a vector of length 1 or 2 with element values to be
'cattr' or 'index' or NA to describe how to bind the returned
data with |
If FUN return a vector, bind can be one of:
"cattr": In this case, the vector will be combined with the cattr
to return a data frame.
"index": In this case, the vector will be combined with the index
to return a "zoo" object.
If FUN return a matrix named x.ret, bind can be one of:
c("index", "cattr"): In this case, the rows of x.ret
will be conbined with the index, and the columns of x.ret will be combined
with the cattr. So a "zoocat" object will be returned.
c("cattr", "index"): In this case, the rows of x.ret will be combined
with the cattr, and the columns of x.ret will be combined with the index.
So a "zoocat" object will be returned, but the core data in the "zoocat" object will
be t(x.ret).
c("cattr", NA): In this case, the rows of x.ret will be combined
with the cattr to return a data frame.
c(NA, "cattr"): In this case, the columns of x.ret will be combined
with the cattr to return a data frame.
c("index", NA): In this case, the rows of x.ret will be combined
with the index to return a "zoo" object.
c(NA, "index"): In this case, the columns of x.ret will be combined
with the index to return a "zoo" object.
Note that if bind is NULL (default), the original returned value of FUN will be returned.
a data frame, a "zoo" object, or a "zoocat" object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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)
apply_core(zc, FUN = colMeans)
apply_core(zc, FUN = colMeans, bind = 'cattr')
apply_core(zc, FUN = rowMeans)
apply_core(zc, FUN = rowMeans, bind = 'index')
apply_core(zc, FUN = function (x) {x*2})
apply_core(zc, FUN = function (x) {x*2}, bind = c('index', 'cattr'))
apply_core(zc, FUN = function (x) {t(x*2)}, bind = c('cattr', 'index'))
apply_core(zc, FUN = function (x) {x*2}, bind = c('index', NA))
apply_core(zc, FUN = function (x) {x[3:4, ]}, bind = c(NA, 'cattr'))
apply_core(zc, FUN = function (x)
{r <- x[3:4, ]
rownames(r) <- c('a', 'b')
return(r)},
bind = c(NA, 'cattr'))
vec <- as.vector(zc[, 1])
apply_core(zc, FUN = function (x) {as.vector(cor(x, vec))}, bind = 'cattr')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.