rmachine-learningr-caretrfe

rfe() function Error: $ operator is invalid for atomic vectors


I have already tried multitude of options but I can't get it working and do not have a clue why. Input dataframe is calculated the same way that Max Kuhn specifies in the caret R documentation. My dataset si formed by 362 predictors and a column of factors with 2 levels. I execute the following code:

set.seed(150)
ctrl_rf <- rfeControl(functions = 'rfFuncs',
                        method = "cv",                       
                        number = 10,
                        rerank = T #Number of folds
                        
                       )
y <- fTR[,'defective'] 
x <- fTR[,1:362]
normalization <- preProcess(x)
x <- predict(normalization, x)
x <- as.data.frame(x)

rferf <- rfe( x,
              y,
                  #sizes = c(10,50,100,200,362),
                  metric = "Kappa",
                  #maximize=TRUE,
                  rfeControl = ctrl_rf) 

However, when executing the code, I keep getting the

Error: $ operator is invalid for atomic vectors'

What am I doing wrong?


Solution

  • Rerun your code after replacing functions = 'rfFuncs' by functions = rfFuncs i.e. remove '' from the function name.