Skip to contents

Functions and methods extracting and modifying positions of 'timeSeries' objects.

Usage

# S4 method for timeSeries
time(x, ...)
# S3 method for timeSeries
time(x) <- value

getTime(x)         
setTime(x) <- value

Arguments

value

a valid value for the time component of x.

x

an object of class timeSeries.

...

optional arguments passed to other methods.

Details

time and time<- are generic functions with methods for class "timeSeries". They get and set the time component of the object.

getTime and setTime are non-generic alternatives are non-generic wrappers of time and time<-, respectively.

There is another generic function time<- defined in package zoo. When that package is loaded its time<- gets the "timeSeries" method. Also, if "time<-" is called with an object from class other than "timeSeries", the call is dispatched to "zoo:time<-" to apply a suitable method.

Value

for time and getTime, a "timeDate" object,

for time<- and and setTime, the modified

"timeSeries" object.

Examples

## Create Dummy 'timeSeries' -      
   X <- timeSeries(matrix(rnorm(24), 12), timeCalendar())
   
## Return Series Positions -
   getTime(X)
#> GMT
#>  [1] [2024-01-01] [2024-02-01] [2024-03-01] [2024-04-01] [2024-05-01]
#>  [6] [2024-06-01] [2024-07-01] [2024-08-01] [2024-09-01] [2024-10-01]
#> [11] [2024-11-01] [2024-12-01]
   time(X)  
#> GMT
#>  [1] [2024-01-01] [2024-02-01] [2024-03-01] [2024-04-01] [2024-05-01]
#>  [6] [2024-06-01] [2024-07-01] [2024-08-01] [2024-09-01] [2024-10-01]
#> [11] [2024-11-01] [2024-12-01]
  
## Add / Subtract one Day from X
   setTime(X) <- time(X) - 24*3600 # sec
   X
#> GMT 
#>                  TS.1         TS.2
#> 2023-12-31 -0.5238281  0.656588464
#> 2024-01-31 -0.4968500  2.548991071
#> 2024-02-29 -1.8060313 -0.034760390
#> 2024-03-31 -0.5820759 -0.669633580
#> 2024-04-30 -1.1088896 -0.007604756
#> 2024-05-31 -1.0149620  1.777084448
#> 2024-06-30 -0.1623095 -1.138607737
#> 2024-07-31  0.5630558  1.367827179
#> 2024-08-31  1.6478175  1.329564791
#> 2024-09-30 -0.7733534  0.336472797
#> 2024-10-31  1.6059096  0.006892838
#> 2024-11-30 -1.1578085 -0.455468738
   time(X) <- time(X) + 24*3600 # sec
   X
#> GMT 
#>                  TS.1         TS.2
#> 2024-01-01 -0.5238281  0.656588464
#> 2024-02-01 -0.4968500  2.548991071
#> 2024-03-01 -1.8060313 -0.034760390
#> 2024-04-01 -0.5820759 -0.669633580
#> 2024-05-01 -1.1088896 -0.007604756
#> 2024-06-01 -1.0149620  1.777084448
#> 2024-07-01 -0.1623095 -1.138607737
#> 2024-08-01  0.5630558  1.367827179
#> 2024-09-01  1.6478175  1.329564791
#> 2024-10-01 -0.7733534  0.336472797
#> 2024-11-01  1.6059096  0.006892838
#> 2024-12-01 -1.1578085 -0.455468738