From 37af635e7fd3f2140dde7e76794640173de96dda Mon Sep 17 00:00:00 2001 From: David Watson Date: Wed, 13 Dec 2023 23:06:47 -0600 Subject: [PATCH] rbindlist --- R/forde.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/R/forde.R b/R/forde.R index 5afac2a5..4c8f7cdd 100644 --- a/R/forde.R +++ b/R/forde.R @@ -96,7 +96,7 @@ forde <- function( # To avoid data.table check issues tree <- n_oob <- cvg <- leaf <- variable <- count <- sd <- value <- psi_cnt <- psi_cat <- f_idx <- sigma <- new_min <- new_max <- mid <- sigma0 <- prob <- - val <- val_count <- k <- cnt <- . <- NULL + val <- val_count <- level <- all_na <- i <- k <- cnt <- . <- NULL # Prelimz if (isTRUE(oob) & !nrow(x) %in% c(arf$num.samples, arf$num.samples/2)) { @@ -290,14 +290,13 @@ forde <- function( all_na[!grepl('\\.5', min), min := min + 0.5] all_na[!grepl('\\.5', max), max := max + 0.5] all_na[, min := min + 0.5][, max := max - 0.5] - all_na <- foreach(i = all_na[, unique(leaf)], .combine = rbind) %:% - foreach(j = all_na[, unique(variable)], .combine = rbind) %do% { - data.table( - leaf = i, - variable = j, - level = all_na[leaf == i & variable == j, seq(min, max)] - ) - } + grd <- expand.grid(leaf = all_na[, unique(leaf)], + variable = all_na[, unique(variable)]) + all_na <- rbindlist(lapply(seq_len(nrow(grd)), function(i) { + data.table( + leaf = grd$leaf[i], variable = grd$variable[i], + level = all_na[leaf == grd$leaf[i] & variable == grd$variable[i], seq(min, max)]) + })) all_na <- merge(all_na, lvl_df, by = c('variable', 'level')) all_na[, level := NULL][, tree := tree] setcolorder(all_na, colnames(dt))