From ab21406f8c2d81b90721c702e42856986ac778d9 Mon Sep 17 00:00:00 2001 From: John Ehrlinger Date: Wed, 25 Jun 2025 10:16:59 -0400 Subject: [PATCH] remove cbind --- R/gg_partial.R | 8 ++++---- R/gg_partialpro.R | 29 +++++++++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/R/gg_partial.R b/R/gg_partial.R index 2ac586e..09c2bdc 100644 --- a/R/gg_partial.R +++ b/R/gg_partial.R @@ -22,10 +22,10 @@ gg_partial = function(part_dta, for (feature in seq(nvars)) { ## Format any continuous features (those with fewer than cat_limit unique values) if (length(unique(part_dta$plotthis[[feature]]$x)) > cat_limit) { - plt.df = as.data.frame(cbind( + plt.df = dplyr::bind_cols( x = part_dta$plotthis[[feature]]$x, yhat = part_dta$plotthis[[feature]]$yhat - )) + ) plt.df$name = names(part_dta$plotthis)[[feature]] cont_list[[feature]] <- plt.df @@ -34,10 +34,10 @@ gg_partial = function(part_dta, ## Though VarPro works with logical or continuous only. Factors are ## one hot encoded internal to the varPro call. - plt.df = as.data.frame(cbind( + plt.df = dplyr::bind_cols( x = factor(part_dta$plotthis[[feature]]$x), yhat = part_dta$plotthis[[feature]]$yhat - )) + ) plt.df$name = names(part_dta$plotthis)[[feature]] cat_list[[feature]] <- plt.df diff --git a/R/gg_partialpro.R b/R/gg_partialpro.R index 5b318a4..3040e3e 100644 --- a/R/gg_partialpro.R +++ b/R/gg_partialpro.R @@ -24,17 +24,16 @@ gg_partialpro = function(part_dta, for (feature in seq(nvars)) { ## Format any continuous features (those with fewer than 10 unique values) if (length(part_dta[[feature]]$xvirtual) > cat_limit) { - plt.df = as.data.frame( - cbind( - variable = part_dta[[feature]]$xvirtual, - parametric = colMeans(part_dta[[feature]]$yhat.par, na.rm = - TRUE), - nonparametric = colMeans(part_dta[[feature]]$yhat.nonpar, na.rm = - TRUE), - causal = colMeans(part_dta[[feature]]$yhat.causal, na.rm = - TRUE) - ) + plt.df = dplyr::bind_cols( + variable = part_dta[[feature]]$xvirtual, + parametric = colMeans(part_dta[[feature]]$yhat.par, na.rm = + TRUE), + nonparametric = colMeans(part_dta[[feature]]$yhat.nonpar, na.rm = + TRUE), + causal = colMeans(part_dta[[feature]]$yhat.causal, na.rm = + TRUE) ) + plt.df$name = names(part_dta)[[feature]] cont_list[[feature]] <- plt.df @@ -46,12 +45,10 @@ gg_partialpro = function(part_dta, cat_feat = list() ## Each yhat has at least 2 columns, for logical values... for (ind in seq(length(unique(part_dta[[feature]]$xorg)))) { - cat_feat[[ind]] = as.data.frame( - cbind( - parametric = part_dta[[feature]]$yhat.par[, ind], - nonparametric = part_dta[[feature]]$yhat.nonpar[, ind], - causal = part_dta[[feature]]$yhat.causal[, ind] - ) + cat_feat[[ind]] = dplyr::bind_cols( + parametric = part_dta[[feature]]$yhat.par[, ind], + nonparametric = part_dta[[feature]]$yhat.nonpar[, ind], + causal = part_dta[[feature]]$yhat.causal[, ind] ) cat_feat[[ind]]$variable <- unique(part_dta[[feature]]$xorg)[ind]