Skip to content

Commit

Permalink
fix mk.lev2
Browse files Browse the repository at this point in the history
  • Loading branch information
jinseob2kim committed May 8, 2024
1 parent 7a55fd0 commit ad342a1
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@
#' @importFrom DT %>%
mk.lev2 <- function(out.old, out.label) {
. <- variable <- val_label <- level <- NULL
label.value <- sapply(out.old, function(x) attr(x, "labels")) %>%
.[!sapply(., is.null)] %>%
sapply(function(x) {
dd <- names(x)
names(dd) <- x
return(dd)
})
label.value <- sapply(out.old, function(x) attr(x, "labels")) %>% .[!sapply(., is.null)] %>% sapply(function(x){dd <- names(x);names(dd) <- x;return(dd)})
label.variable <- sapply(out.old, function(x) attr(x, "label")) %>% .[!sapply(., is.null)]

for (v in names(label.variable)) {
for (v in names(label.variable)){
out.label[variable == v, var_label := label.variable[v]]
}
for (v in names(label.value)) {
out.label[variable == v, val_label := label.value[[v]][level]]
for (v in names(label.value)){
if (is.factor(out.old[[v]])){
out.label[variable == v, val_label := label.value[[v]][level]]
}
}

return(out.label[])
}


0 comments on commit ad342a1

Please sign in to comment.