getAdmLimits: Get Admission time

View source: R/getAdmLimits.R

getAdmLimitsR Documentation

Get Admission time

Description

Adds first admission date and last discharge date to a sequence of admissions. The default input data.table is the current standard by which admissions are available in Statistics Denmark.

Usage

getAdmLimits(
  dt,
  pnr = "pnr",
  inddto = "inddto",
  uddto = "uddto",
  keep = NULL,
  collapse = FALSE,
  error = "warn"
)

Arguments

dt

data.table containing the variables

pnr

Variable with ID for each subject/group (default is pnr).

inddto

Variable with entry times. Must be date or numeric (default is inddto).

uddto

Variable with exit times. Must be date or numeric (default is uddto).

keep

Vector of names of variables of dt to keep in the output

collapse

if TRUE return only the lines with non-overlapping admissions

error

Character. One of "warn", "remove" remove lines with errors, "flag" add a new variable called error. An error is defined as either a missing value in either inddto or uddto or when inddto>uddto.

Value

data.table with two new variables first.indate and last.outdate.

Author(s)

Thomas A. Gerds <tag@biostat.ku.dk>

Examples

set.seed(8)
lpr <- simAdmissionData(10)
## Variables have default names
adm <- getAdmLimits(lpr)

## with errors
lpr1 <- lpr
lpr1 <- lpr1[uddto>as.Date("2010-01-01"),uddto:=NA]
adm1 <- getAdmLimits(lpr1)
adm1 <- getAdmLimits(lpr1,error="remove")
adm1 <- getAdmLimits(lpr1,error="flag")

## case where Variables have custom names
data.table::setnames(lpr, c('pnr','inddto','uddto'), c('personid', 'Entrydate','Outdate'))
adm2 <- getAdmLimits(lpr,pnr='personid',inddto='Entrydate',uddto='Outdate')

## duplicated and overlap
set.seed(8)
lpr3 <- simAdmissionData(10)
lpr3 <- lpr3[sample(1:NROW(lpr3),replace=TRUE,size=round(NROW(lpr3)*1.5))]
adm3 <- getAdmLimits(lpr3,collapse=TRUE)


tagteam/heaven documentation built on Oct. 24, 2024, 7:40 p.m.