knitr::opts_chunk$set(echo = TRUE) knitr::opts_chunk$set(message = FALSE) # knitr::opts_chunk$set(results = 'hide')
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
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.
For the transformation into the relative timescale (
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
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 class(my_sim_datetime)
All remaining functions of simtimer take a
sim_datetime as argument.
For the opposite transformation (
date_time) use the corresponding function
as.datetime() with the same
You can extract the time (in seconds) of a
sim_datetime element by using the function
sim_time(). It returns how many seconds have past since the last "beginning of a day" depending on the time-part of your
origin_date ("00:00:00" is recommended).
You can extract the weekday of a
sim_datetime elemet by using the function
sim_wday(). It returns the weekday of your
In order to count the days that have passed since the beginning (your
sim_date(). To be more precise - the function returns the number of
that have passed since your
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.