transform_time_id: Transforming a series of time or datetime to time indexes

View source: R/transform_time_id.R

transform_time_idR Documentation

Transforming a series of time or datetime to time indexes

Description

This function transforms a series of time or datetime to time indexes.

Usage

transform_time_id(obsTime, timeUnit, timeStep)

Arguments

obsTime

Date/Datetime/Numeric. A vector of observed time of hot spots. If timeUnit is "n", obsTime needs to be a numeric vector, otherwise, it needs to be in date or datetime format.

timeUnit

Character. The unit of time, one of "s" (seconds), "m"(minutes), "h"(hours), "d"(days) and "n"(numeric).

timeStep

Numeric (>0). Number of units of timeUnit in a time step.

Details

The earliest time is assigned with a time index 1. The difference between any other time to the earliest time is transformed using the timeUnit and divided by the timeStep. These differences are floored to integer and used as the time indexes.

Value

Integer. A vector of time indexes.

Examples


# Define obsTime
obsTime <- as.Date(c("2020-01-01",
                     "2020-01-02",
                     "2020-01-04"))

# Transform it to time index under different settings
transform_time_id(obsTime, "h", 1)
transform_time_id(obsTime, "m", 60)
transform_time_id(obsTime, "s", 3600)

# Define numeric obsTime
obsTime <- c(1,
             1.5,
             4.5,
             6)

# Transform it to time index under different settings
transform_time_id(obsTime, "n", 1)
transform_time_id(obsTime, "n", 1.5)



TengMCing/spotoroo documentation built on Nov. 21, 2024, 4:17 a.m.