make_reop_long | R Documentation |
Convert reoperation columns from wide to long format
make_reop_long(df, removeFALSE = FALSE)
df |
a data.table |
removeFALSE |
a logical vector indicating whether or not to remove rows with a FALSE value. |
The data from the data table is then 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 reoperation
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 reoperation") from
a missing value ("do not know if there was a reoperation").
Note that this function does not reorder nreoperation
after converting to long and removing records with
NA, FALSE, or both. This is because the third reoperation (reoperation3
) has significance as representing
3 or more reoperations.
a data.table
x <- data.table::data.table(caseid = c(1,2,3,4),
reoperation1 = c(TRUE, TRUE, FALSE, NA),
retorpodays = c(10, 7, NA, NA),
reoporcpt1 = c("44005", "37211", NA, NA),
retorrelated = c(TRUE, TRUE, NA, NA),
reoporicd91 = c("K56.69","T82.868A", NA, NA),
reopor1icd101 = c("K56.59", "T82.868A", NA, NA),
reoperation2 = c(TRUE, TRUE, FALSE, NA),
retor2podays = c(10, 7, NA, NA),
reopor2cpt1 = c("44005", "37211", NA, NA),
retor2related = c(TRUE, TRUE, NA, NA),
reopor2icd91 = c("K56.69","T82.868A", NA, NA),
reopor2icd101 = c("K56.59", "T82.868A", NA, NA),
reoperation3 = c(TRUE, TRUE, FALSE, NA),
retor3podays = c(10, 7, NA, NA),
reopor3cpt1 = c("44005", "37211", NA, NA),
retor3related = c(TRUE, TRUE, NA, NA),
reopor3icd91 = c("K56.69","T82.868A", NA, NA),
reopor3icd101 = c("K56.59", "T82.868A", NA, NA))
nsqipr:::make_reop_long(x)
nsqipr:::make_reop_long(x, TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.