forked from symbolrush/simTimeR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
59 lines (40 loc) · 1.54 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
library(simtimer)
```
# simtimer
simtimer in 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.
## Installation
You can install simtimer from `CRAN` or `github` with:
```{r gh-installation, eval = FALSE}
install.packages("simtimer")
# install.packages("devtools")
devtools::install_github("ims-fhs/simtimer")
```
## Example
Simtimer allows transformation between datetimes (POSIXt) and sim_datetimes (integer) with
`as.sim_datetime()` and `as.datetime()`.
```{r example}
origin_date <- as.POSIXct("2016-01-01 00:00:00", tz = "UTC")
my_datetime <- as.POSIXct("2016-01-02 01:01:01", tz = "UTC")
my_simdatetime <- as.sim_datetime(my_datetime, origin_date)
my_simdatetime
```
```{r}
as.datetime(my_simdatetime, origin_date)
```
Simtimer allows to manipulate sim_datetimes and extract parts of sim_datetimes with
`sim_time()`, `sim_wday()` and `sim_date()`.
```{r}
sim_time(my_simdatetime)
sim_wday(my_simdatetime, origin_date)
sim_date(my_simdatetime)
```