Skip to content

Instantly share code, notes, and snippets.

@timvink
timvink / BepaalBezetting
Created October 30, 2013 09:45
Functie om de bezetting te bepalen, gegeven een begintijd en eindtijd.
BepaalBezetting <- function(DT_bezetting=kliniek) {
vecTime <- seq.POSIXt(min(DT_bezetting$Ingangsdatumtijd)-60, max(DT_bezetting$Einddatumtijd)+60, by = "mins")
Start <- setkey(DT_bezetting, Ingangsdatumtijd)
Start <- Start[J(vecTime),.N] # Per minuut, het aantal gestarte mutaties.
setnames(Start,"N","Start") # kolomnaam anders
setnames(Start,"Ingangsdatumtijd","Minuut") # kolomnaam anders
Eind <- setkey(DT_bezetting, Einddatumtijd)
Eind <- Eind[J(vecTime),.N] # Per minuut, het aantal gestarte mutaties.
setnames(Eind,"N","Eind") # kolomnaam anders
setnames(Eind,"Einddatumtijd","Minuut") # kolomnaam anders
@timvink
timvink / package installed test
Created October 9, 2013 14:05
Test whether package is installed. If not, install. Then Load. example use: pkgTest("ggplot2") instead of normal library("ggplot2").
pkgTest <- function(x)
{
if (!require(x,character.only = TRUE))
{
install.packages(x,dep=TRUE, repos="http://cran-mirror.cs.uu.nl/")
if(!require(x,character.only = TRUE)) stop("Package not found, cannot be installed")
}
}