Skip to contents

Get the data from a Lagged object and ensure that the lag dimension is named

Usage

dataWithLagNames(object, prefix = "Lag_")

Arguments

object

an object inheriting from "Lagged".

prefix

a character string.

Details

dataWithLagNames() extracts the data part from a lagged object and gives names to the lag dimension, if it is not already named.

This function is mainly used for programming, particularly in show() methods for lagged objects..

Value

The data part with names as described in Details.

Author

Georgi N. Boshnakov

Examples

x <- Lagged(drop(acf(ldeaths, plot = FALSE)$acf))
## there are no names for the lags:
names(x) # NULL
#> NULL
## but the print method inserts default "Lag_N" names
x
#> An object of class "Lagged1d"
#> Slot *data*: 
#>        Lag_0        Lag_1        Lag_2        Lag_3        Lag_4        Lag_5 
#>  1.000000000  0.755051141  0.396956836  0.019395714 -0.355897989 -0.608566374 
#>        Lag_6        Lag_7        Lag_8        Lag_9       Lag_10       Lag_11 
#> -0.681383469 -0.607909875 -0.378212377 -0.012975866  0.383252644  0.650206704 
#>       Lag_12       Lag_13       Lag_14       Lag_15       Lag_16       Lag_17 
#>  0.723167071  0.638001465  0.371577811  0.009467461 -0.293699737 -0.496742216 
#>       Lag_18 
#> -0.585558984 
## This sets the names to their defaults:
x1 <- dataWithLagNames(x)
names(x1)
#>  [1] "Lag_0"  "Lag_1"  "Lag_2"  "Lag_3"  "Lag_4"  "Lag_5"  "Lag_6"  "Lag_7" 
#>  [9] "Lag_8"  "Lag_9"  "Lag_10" "Lag_11" "Lag_12" "Lag_13" "Lag_14" "Lag_15"
#> [17] "Lag_16" "Lag_17" "Lag_18"
## ... and this sets non-default prefix:
x2 <- dataWithLagNames(x, "L")
names(x2)
#>  [1] "L0"  "L1"  "L2"  "L3"  "L4"  "L5"  "L6"  "L7"  "L8"  "L9"  "L10" "L11"
#> [13] "L12" "L13" "L14" "L15" "L16" "L17" "L18"
x2
#>           L0           L1           L2           L3           L4           L5 
#>  1.000000000  0.755051141  0.396956836  0.019395714 -0.355897989 -0.608566374 
#>           L6           L7           L8           L9          L10          L11 
#> -0.681383469 -0.607909875 -0.378212377 -0.012975866  0.383252644  0.650206704 
#>          L12          L13          L14          L15          L16          L17 
#>  0.723167071  0.638001465  0.371577811  0.009467461 -0.293699737 -0.496742216 
#>          L18 
#> -0.585558984