[R] discourage use of regex for fixed string comparisons (#8736)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user