Skip to contents

Converts numeric, Date, or POSIXt values to elapsed numeric time while retaining origin, unit, and input-class metadata. Input order is never changed: non-increasing time values are rejected.

Usage

gp_time_index(time, unit = "auto")

Arguments

time

Numeric, Date, or POSIXt vector in strictly increasing order.

unit

Time unit for Date or POSIXt inputs. "auto" uses days for Date values, seconds for POSIXt values, and the native scale for numeric inputs.

Value

A numeric vector of elapsed time with class gaussianprocesses_time_index and time metadata in attributes.

Details

Time values are never sorted silently. Non-increasing input is rejected so the temporal order supplied by the user remains explicit.

Stability

Stable: from version 1.0.0 this interface changes incompatibly only in a major release, after a deprecation period. Results and options that concern an experimental model class, kernel, or argument follow that interface's tier. See gaussianprocesses-package for the policy.

Examples

gp_time_index(as.Date("2026-01-01") + c(0, 1, 7))
#> [1] 0 1 7
#> attr(,"origin")
#> [1] "2026-01-01"
#> attr(,"unit")
#> [1] "days"
#> attr(,"input_type")
#> [1] "Date"
#> attr(,"class")
#> [1] "gaussianprocesses_time_index" "numeric"                     

gp_time_index(
  as.POSIXct("2026-01-01 00:00", tz = "UTC") + c(0, 3600, 7200),
  unit = "hours"
)
#> [1] 0 1 2
#> attr(,"origin")
#> [1] "2026-01-01 UTC"
#> attr(,"unit")
#> [1] "hours"
#> attr(,"input_type")
#> [1] "POSIXt"
#> attr(,"class")
#> [1] "gaussianprocesses_time_index" "numeric"