Extracting/Replacing the Core Data of Objects

Description

Generic functions for extracting the core data contained in a (more complex) object and replacing it.

Usage

coredata(x, ...)
coredata(x) <- value

Arguments

x an object.
further arguments passed to methods.
value a suitable value object for use with x.

Value

In zoo, there are currently coredata methods for time series objects of class “zoo”, “ts”, “its”, “irts”, all of which strip off the index/time attributes and return only the observations. The are also corresponding replacement methods for these classes.

See Also

zoo

Examples

library("zoo")

suppressWarnings(RNGversion("3.5.0"))
set.seed(1)

x.date <- as.Date(paste(2003, rep(1:4, 4:1), seq(1,20,2), sep = "-"))
x <- zoo(matrix(rnorm(20), ncol = 2), x.date)

## the full time series
x
                                 
2003-01-01 -0.6264538  1.51178117
2003-01-03  0.1836433  0.38984324
2003-01-05 -0.8356286 -0.62124058
2003-01-07  1.5952808 -2.21469989
2003-02-09  0.3295078  1.12493092
2003-02-11 -0.8204684 -0.04493361
2003-02-13  0.4874291 -0.01619026
2003-03-15  0.7383247  0.94383621
2003-03-17  0.5757814  0.82122120
2003-04-19 -0.3053884  0.59390132
## and only matrix of observations
coredata(x)
            [,1]        [,2]
 [1,] -0.6264538  1.51178117
 [2,]  0.1836433  0.38984324
 [3,] -0.8356286 -0.62124058
 [4,]  1.5952808 -2.21469989
 [5,]  0.3295078  1.12493092
 [6,] -0.8204684 -0.04493361
 [7,]  0.4874291 -0.01619026
 [8,]  0.7383247  0.94383621
 [9,]  0.5757814  0.82122120
[10,] -0.3053884  0.59390132
## change the observations
coredata(x) <- matrix(1:20, ncol = 2)
x
                
2003-01-01  1 11
2003-01-03  2 12
2003-01-05  3 13
2003-01-07  4 14
2003-02-09  5 15
2003-02-11  6 16
2003-02-13  7 17
2003-03-15  8 18
2003-03-17  9 19
2003-04-19 10 20