Error in { : object 'v2' not found in caret

randomforest

#1

Hi everybody,
There are anyone get this kind of error when run randomforest model in caret?

library(randomForest)
library(mlbench)
library(caret)
library(lattice)
 
# Load Dataset
data(Sonar)
dataset <- Sonar
x <- dataset[,1:60]
y <- dataset[,61]

control <- trainControl(method="repeatedcv", 
                        number=10, 
                        repeats=3)
metric <- "Accuracy"
set.seed(123)
mtry <- sqrt(ncol(x))
tunegrid <- expand.grid(.mtry=mtry)
rf_default <- train(Class~., 
                      data=dataset, 
                      method="rf", 
                      metric=metric, 
                      tuneGrid=tunegrid, 
                      trControl=control)
print(rf_default)

And error as below:

Error in { : object 'v2' not found


#2

I just ran your code exactly as is and it worked. Does it fail with that error when you run that code? If not, you might have an illegal variable name in the dataset you're using.