[R] discourage use of regex for fixed string comparisons (#8736)

This commit is contained in:
James Lamb
2023-01-30 04:47:21 -06:00
committed by GitHub
parent 1325ba9251
commit 0d8248ddcd
8 changed files with 20 additions and 19 deletions

View File

@@ -7,7 +7,7 @@ train <- train[, -1]
test <- test[, -1]
y <- train[, ncol(train)]
y <- gsub('Class_', '', y)
y <- gsub('Class_', '', y, fixed = TRUE)
y <- as.integer(y) - 1 # xgboost take features in [0,numOfClass)
x <- rbind(train[, -ncol(train)], test)

View File

@@ -87,7 +87,7 @@ For that purpose, we will:
```{r classToIntegers}
# Convert from classes to numbers
y <- train[, nameLastCol, with = FALSE][[1]] %>%
gsub('Class_', '', .) %>%
gsub('Class_', '', ., fixed = TRUE) %>%
as.integer %>%
subtract(., 1)