A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cran.rstudio.com/web/packages/microbenchmark/../simtimer/vignettes/simtimer.html below:

simtimer

simtimer is a little R package designed to simplify (and speeding up) calculating time intervals in discrete event simulations.

Discrete event simulations is a simulation paradigm that is based on the evaluation of events taking place in a time-specific order. Therefore a discrete event simulation calculates many time intervals. simtimer handles dates and times as integers. This makes working with time intervals as easy (and as fast) as subtracting integers.

simtimer uses an origin_date and calculates all dates and times referring to that origin_date.

The applications of simtimer are discrete event simulations representing a timerange of several minutes to years. For such problems, the time dimension might preferably be represented as a relative timescale (integer) than a series of date_time objects (POSIXt). simtimer is a basic tool to transform date_times to a relative timescale in seconds (sim_datetime) and vice versa. Additionally simtimer allows to extract elements of a sim_datetime such as time, weekday and date.

Basic transformation

For the transformation into the relative timescale (date_time -> sim_datetime) use the corresponding function as.sim_datetime(). This function expects an origin_date of choice to be predefined. This origin_date should be earlier in time than the following date_time-elements.

library(simtimer)
origin_date <- as.POSIXct("2017-01-01 00:00:00", tz = "UTC")
my_datetime <- c(as.POSIXct("2017-01-01 02:00:00", tz = "UTC"), 
                 as.POSIXct("2017-02-27 20:53:20", tz = "UTC"),
                 as.POSIXct("2017-08-20 11:33:20", tz = "UTC"),
                 as.POSIXct("2018-01-06 08:53:20", tz = "UTC"))
my_sim_datetime <- as.sim_datetime(my_datetime, origin_date)
my_sim_datetime
## [1]     7200  5000000 20000000 32000000
## [1] "integer"

All remaining functions of simtimer take a sim_datetime as argument.

For the opposite transformation (sim_datetime -> date_time) use the corresponding function as.datetime() with the same origin_date.

as.datetime(my_sim_datetime, origin_date)
## [1] "2017-01-01 02:00:00 UTC" "2017-02-27 20:53:20 UTC"
## [3] "2017-08-20 11:33:20 UTC" "2018-01-06 08:53:20 UTC"

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4