Skip to contents

Create Time Series

Usage

series(object, time, calendar, ...)

# S4 method for class 'array,RataDie,missing'
series(object, time, names = NULL)

# S4 method for class 'array,numeric,TimeScale'
series(object, time, calendar, scale = 1, names = NULL)

# S4 method for class 'matrix,numeric,TimeScale'
series(object, time, calendar, scale = 1, names = NULL)

# S4 method for class 'matrix,RataDie,missing'
series(object, time, names = NULL)

# S4 method for class 'numeric,numeric,TimeScale'
series(object, time, calendar, scale = 1, names = NULL)

# S4 method for class 'numeric,RataDie,missing'
series(object, time, names = NULL)

# S4 method for class 'data.frame,numeric,TimeScale'
series(object, time, calendar, scale = 1, names = NULL)

# S4 method for class 'data.frame,RataDie,missing'
series(object, time, names = NULL)

Arguments

object

A numeric vector, matrix or array of the observed time-series values. A data.frame will be coerced to a numeric matrix via data.matrix().

time

A numeric vector of (decimal) years or a RataDie object (see fixed()).

calendar

A TimeScale object specifying the calendar of time (see calendar()). If missing, time must be a RataDie object.

...

Currently not used.

names

A character string specifying the names of the time series.

scale

A length-one numeric vector specifying the number of years represented by one unit. It should be a power of 10 (i.e. 1000 means ka).

Value

A TimeSeries object.

Details

Data will be sorted in chronological order.

Author

N. Frerebeau

Examples

## Create time-series of 20 observations

## Univariate
## Sampled every years starting from 1029 BCE
(X <- series(rnorm(30), time = 1029:1000, calendar = BCE()))
#> 30 x 1 x 1 time series observed between -1029 CE and -1000 CE

## Terminal and sampling times (returns rata die)
start(X)
#> [1] -376199
end(X)
#> [1] -365607
time(X)
#> Rata die: number of days since 01-01-01 (Gregorian)
#>  [1] -376199 -375834 -375468 -375103 -374738 -374373 -374007 -373642 -373277
#> [10] -372912 -372546 -372181 -371816 -371451 -371085 -370720 -370355 -369990
#> [19] -369624 -369259 -368894 -368529 -368163 -367798 -367433 -367068 -366702
#> [28] -366337 -365972 -365607
span(X)
#> [1] 10592

## Multivariate
## Sampled every century starting from 1000 CE
(Y <- series(matrix(rnorm(90), 30, 3), time = 1000:1029, calendar = CE()))
#> 30 x 3 x 1 time series observed between 1000 CE and 1029 CE

## Terminal and sampling times (returns Gregorian Common Era years)
start(Y, calendar = CE())
#> [1] 1000
end(Y, calendar = CE())
#> [1] 1029
time(Y, calendar = CE())
#>  [1] 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
#> [16] 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
span(Y, calendar = CE())
#> [1] 29

## Coerce to data frame
df <- as.data.frame(Y, calendar = BP())
head(df)
#>   time series variable       value
#> 1  950     S1        A -0.31455274
#> 2  949     S1        A -0.48054281
#> 3  948     S1        A  0.83625425
#> 4  947     S1        A -0.05234929
#> 5  946     S1        A  0.95195762
#> 6  945     S1        A  1.49451280