title: Get the most important variable names from varImp()
body: <p>I am working with the function varImp(). </p>
  
  <p>I fit a tree, and then use varImp() to see which variables are most important. I would like to extract the most important variable names from the output of varImp(). But the output appears to be a list and there is no way to get the variable names, only the numerical weights of how important the variables are.</p>
  
  <p>I have tried converting the output to a data frame and also using names() but neither allows me to get the important variable names.</p>
  
  <p>Here's an example: </p>
  
  <pre><code>&gt; # Sample data
  &gt; head(Orthodont)
  Grouped Data: distance ~ age | Subject
    distance age Subject  Sex
  1     26.0   8     M01 Male
  2     25.0  10     M01 Male
  3     29.0  12     M01 Male
  4     31.0  14     M01 Male
  5     21.5   8     M02 Male
  6     22.5  10     M02 Male
  &gt; sample_tree &lt;- rpart(distance ~ ., data = Orthodont)
  &gt; varImp(sample_tree)
            Overall
  age     1.1178243
  Sex     0.5457834
  Subject 2.8446154
  &gt; names(varImp(sample_tree))
  [1] "Overall"
  &gt; as.data.frame(varImp(sample_tree))
            Overall
  age     1.1178243
  Sex     0.5457834
  Subject 2.8446154
  &gt; # What I want are the names of the two most important variables.
  </code></pre>