0

I have been using caret for prediction. It has the var.imp function to extract 'important' variables from the final model. Example below:

library(mlbench)
library(caret)
set.seed(1234)

data(Sonar)   
Sonar = Sonar[, 1:6]
inTraining <- createDataPartition(Sonar$V6, p = 0.75, list = FALSE)
training <- Sonar[inTraining, ]
testing <- Sonar[-inTraining, ]
modelFit <- train( V6~.,data=training, method="rf")  
varImp(modelFit)

I did the above, and then run the following code to extract these retained variables

ImpMeasure<-data.frame(varImp(modelFit)$importance)
    ImpMeasure$Vars<-row.names(ImpMeasure)

However they all have `` around them so I can't merge these variables with their identifiers.

`V1` `V2` `V3`

How do I remove the `` ?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
ayeepi
  • 135
  • 8
  • Sorry yes - `V1` is correct. How do I get rid of the `` around the elements? – ayeepi Mar 09 '20 at 11:45
  • I just want to merge this set of variables (V1, V2, V3) with another dataframe of these variables, but the latter dataframe doesn't have `` so it wont merge – ayeepi Mar 10 '20 at 16:24
  • 2
    Running the code from your example creates clean variable names for me, I am suspecting the issue is created in a part of your code, that you haven't shared. Usually backticks in R are used for non-syntactic variable names (i.e. starting with a number), looking [here](https://stackoverflow.com/questions/36220823/what-do-backticks-do-in-r) or reading the documentation on `?Quotes` might help. – Till Mar 10 '20 at 18:44

0 Answers0