-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
419 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#' @keywords internal | ||
.matchit <- function(x, id, code, regex) { | ||
### Deal with missing codes | ||
mvb <- id | ||
backup <- x[, ..mvb] | ||
backup <- unique(backup) | ||
x <- stats::na.omit(x) | ||
# If there are no rows left (= user passed missing data only), then error: | ||
if (nrow(x) == 0) stop("No non-missing data, please check your input data", call. = FALSE) | ||
|
||
### Get list of unique codes used in dataset that match comorbidities | ||
..cd <- unique(x[[code]]) | ||
loc <- sapply(X = regex, FUN = function(p) stringi::stri_subset_regex(str = ..cd, pattern = p)) | ||
loc <- utils::stack(loc) | ||
data.table::setDT(loc) | ||
data.table::setnames(x = loc, new = c(code, "ind")) | ||
|
||
### Merge list with original data.table (data.frame) | ||
x <- merge(x, loc, all.x = TRUE, allow.cartesian = TRUE, by = code) | ||
x[, (code) := NULL] | ||
x <- unique(x) | ||
|
||
### Spread wide | ||
mv <- c(id, "ind") | ||
xin <- x[, ..mv] | ||
xin[, value := 1L] | ||
x <- data.table::dcast.data.table(xin, stats::as.formula(paste(id, "~ ind")), fill = 0) | ||
if (!is.null(x[["NA"]])) x[, `NA` := NULL] | ||
|
||
### Restore IDs | ||
x <- merge(x, backup, by = id, all.y = TRUE, ) | ||
data.table::setnafill(x = x, type = "const", fill = 0L) | ||
|
||
### Add missing columns | ||
for (col in names(regex)) { | ||
if (is.null(x[[col]])) x[, (col) := 0L] | ||
} | ||
data.table::setcolorder(x, c(id, names(regex))) | ||
|
||
### Return | ||
return(x) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.