Skip to contents

Class FlexibleLagged.

Objects from the Class

Objects can be created by calls of the form new("FlexibleLagged", data, ...), see also convenience function Lagged,

"FlexibleLagged" is used mainly in programming as a superclass of classes which need to inherit from all "Lagged" classes. It can represent objects from any subclass of "Lagged". Methods are defined, such that the internal representation is transparent.

Slots

data:

Object of class "Lagged" ~~

Extends

Class "Lagged", directly.

Methods

[

signature(x = "FlexibleLagged", i = "ANY"): ...

[

signature(x = "FlexibleLagged", i = "missing"): ...

[<-

signature(x = "FlexibleLagged", i = "missing"): ...

[<-

signature(x = "FlexibleLagged", i = "numeric"): ...

Author

Georgi N. Boshnakov

Examples

## Lagged1d
v <- 1:12
v_lagged <- Lagged(v)
v_lagged
#> An object of class "Lagged1d"
#> Slot *data*: 
#>  Lag_0  Lag_1  Lag_2  Lag_3  Lag_4  Lag_5  Lag_6  Lag_7  Lag_8  Lag_9 Lag_10 
#>      1      2      3      4      5      6      7      8      9     10     11 
#> Lag_11 
#>     12 
identical(v_lagged, new("Lagged1d", data = v)) # TRUE
#> [1] TRUE
v_lagged[0:2] # v[1:3]
#> [1] 1 2 3
v_lagged[[0]] # 1
#> [1] 1

## Lagged2d
m <- matrix(1:12, nrow = 4)
m_lagged <- Lagged(m)
m_lagged
#> An object of class "Lagged2d"
#> Slot *data*: 
#>  Lag_0 Lag_1 Lag_2
#>      1     5     9
#>      2     6    10
#>      3     7    11
#>      4     8    12
identical(m_lagged, new("Lagged2d", data = m)) # TRUE
#> [1] TRUE
m_lagged[0] # matrix with 1  column
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3
#> [4,]    4
m_lagged[[0]] # numeric
#> [1] 1 2 3 4

## Lagged3d
a <- array(1:24, dim = c(2, 3, 4))
a_lagged <- Lagged(a)
identical(a_lagged, new("Lagged3d", data = a)) # TRUE
#> [1] TRUE

dim(a_lagged[0]) # c(2,3,1)
#> [1] 2 3 1
a_lagged[0]
#> , , 1
#> 
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
#> 
a[ , , 1, drop = FALSE]
#> , , 1
#> 
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
#> 

dim(a_lagged[[0]]) # c(2,3)
#> [1] 2 3
a_lagged[[0]]
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
a[ , , 1, drop = TRUE]
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6

## as above "FlexibleLagged"
## 1d
v_flex <- new("FlexibleLagged", data = v)
identical(v_flex@data, v_lagged) # TRUE
#> [1] TRUE
v_flex[0]   # = v_lagged[0]
#> [1] 1
v_flex[[0]] # = v_lagged[[0]]
#> [1] 1

## 2d
m_flex <- new("FlexibleLagged", data = m)
identical(m_flex@data, m_lagged) # TRUE
#> [1] TRUE
m_flex[0]   # = m_lagged[0]
#>      [,1]
#> [1,]    1
#> [2,]    2
#> [3,]    3
#> [4,]    4
m_flex[[0]] # = m_lagged[[0]]
#> [1] 1 2 3 4

## 3d
a_flex <- new("FlexibleLagged", data = a)
identical(a_flex@data, a_lagged) # TRUE
#> [1] TRUE
a_flex[0]   # = a_lagged[0]
#> , , 1
#> 
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6
#> 
a_flex[[0]] # = a_lagged[[0]]
#>      [,1] [,2] [,3]
#> [1,]    1    3    5
#> [2,]    2    4    6