[R] fix uses of 1:length(x) and other small things (#5992)

This commit is contained in:
James Lamb
2020-08-08 20:31:33 +01:00
committed by GitHub
parent 801e6b6800
commit 589b385ec6
7 changed files with 15 additions and 15 deletions

View File

@@ -124,7 +124,7 @@ xgb.plot.shap <- function(data, shap_contrib = NULL, features = NULL, top_n = 1,
stop("shap_contrib is not compatible with the provided data")
nsample <- if (is.null(subsample)) min(100000, nrow(data)) else as.integer(subsample * nrow(data))
idx <- sample(1:nrow(data), nsample)
idx <- sample(seq_len(nrow(data)), nsample)
data <- data[idx, ]
if (is.null(shap_contrib)) {
@@ -162,7 +162,7 @@ xgb.plot.shap <- function(data, shap_contrib = NULL, features = NULL, top_n = 1,
data <- data[, features, drop = FALSE]
cols <- colnames(data)
if (is.null(cols)) cols <- colnames(shap_contrib)
if (is.null(cols)) cols <- paste0('X', 1:ncol(data))
if (is.null(cols)) cols <- paste0('X', seq_len(ncol(data)))
colnames(data) <- cols
colnames(shap_contrib) <- cols