make_readm_long: Convert readmission columns from wide to long format

make_readm_longR Documentation

Convert readmission columns from wide to long format

Description

Convert readmission columns from wide to long format

Usage

make_readm_long(df, removeFALSE = FALSE)

Arguments

df

a data.table

removeFALSE

a logical vector indicating whether or not to remove rows with a FALSE value.

Details

The data from the data table is melted into a long format with caseid as the ID variable to allow rejoining to the main table. After melting, rows with missing values are omitted to reduce the size of the table. Rows where readmission are false may also be removed with removeFALSE to reduce table size if desired, but note this results in an inability to a clarify a known FALSE ("did not have a readmission") from a missing value ("do not know if there was a readmission").

Value

a data.table

Examples

x <- data.table::data.table(caseid = c(1,2,3,4),
readmission1 = c(TRUE, TRUE, FALSE, NA),
readmpodays1 = c(10, 7, NA, NA),
readmrelated1 = c(TRUE, FALSE, NA, NA),
readmsuspreason1 = c("Reason", "Reason", NA, NA),
readmrelicd91 = c("111", "222", NA, NA),
readmrelicd101 = c("1111","2222", NA, NA),
unplannedreadmission1 = c(TRUE, FALSE, NA, NA),
readmunrelsusp1 = c("Reason", NA, NA, NA),
readmunrelicd91 = c("111", NA, NA, NA),
readmunrelicd101 = c("1111",NA,NA,NA),
readmission2 = c(TRUE, TRUE, FALSE, NA),
readmpodays2 = c(10, 7, NA, NA),
readmrelated2 = c(TRUE, FALSE, NA, NA),
readmsuspreason2 = c("Reason", "Reason", NA, NA),
readmrelicd92 = c("111", "222", NA, NA),
readmrelicd102 = c("1111","2222", NA, NA),
unplannedreadmission2 = c(TRUE, FALSE, NA, NA),
readmunrelsusp2 = c("Reason", NA, NA, NA),
readmunrelicd92 = c("111", NA, NA, NA),
readmunrelicd102 = c("1111",NA,NA,NA),
readmission3 = c(TRUE, TRUE, FALSE, NA),
readmpodays3 = c(10, 7, NA, NA),
readmrelated3 = c(TRUE, FALSE, NA, NA),
readmsuspreason3 = c("Reason", "Reason", NA, NA),
readmrelicd93 = c("111", "222", NA, NA),
readmrelicd103 = c("1111","2222", NA, NA),
unplannedreadmission3 = c(TRUE, FALSE, NA, NA),
readmunrelsusp3 = c("Reason", NA, NA, NA),
readmunrelicd93 = c("111", NA, NA, NA),
readmunrelicd103 = c("1111",NA,NA,NA),
readmission4 = c(TRUE, TRUE, NA, NA),
readmpodays4 = c(10, 7, NA, NA),
readmrelated4 = c(TRUE, FALSE, NA, NA),
readmsuspreason4 = c("Reason", "Reason", NA, NA),
readmrelicd94 = c("111", "222", NA, NA),
readmrelicd104 = c("1111","2222", NA, NA),
unplannedreadmission4 = c(TRUE, FALSE, NA, NA),
readmunrelsusp4 = c("Reason", NA, NA, NA),
readmunrelicd94 = c("111", NA, NA, NA),
readmunrelicd104 = c("1111",NA,NA,NA),
readmission5 = c(TRUE, TRUE, FALSE, NA),
readmpodays5 = c(10, 7, NA, NA),
readmrelated5 = c(TRUE, FALSE, NA, NA),
readmsuspreason5 = c("Reason", "Reason", NA, NA),
readmrelicd95 = c("111", "222", NA, NA),
readmrelicd105 = c("1111","2222", NA, NA),
unplannedreadmission5 = c(TRUE, FALSE, NA, NA),
readmunrelsusp5 = c("Reason", NA, NA, NA),
readmunrelicd95 = c("111", NA, NA, NA),
readmunrelicd105 = c("1111",NA,NA,NA))

nsqipr:::make_readm_long(x)
nsqipr:::make_readm_long(x, TRUE)


dylanrussellmd/nsqipr documentation built on Oct. 13, 2023, 11:01 a.m.