title: column subsets and indexes in R in modifying a data frame
body: <p>For the dataset in R, mtcars, I am trying to make a subset of the data frame, from column 1, 2, and 8 and 9. I want to index columns 8 and 9 so i can call upon one or the other in my function in order to get a certain output.</p>
  
  <p>so I did</p>
  
  <pre><code>highestmpg &lt;- function(cyl, type) {
  
    type &lt;- mtcars[, c(8, 9)]
    df &lt;- mtcars[, c(1, 2, type)]
  </code></pre>
  
  <p>I got an error this far into the function</p>
  
  <blockquote>
    <p>Error in .subset(x, j) : invalid subscript type 'list'</p>
  </blockquote>
  
  <p>I don't understand this error, can someone help me figure out how to circumvent this error?</p>
  
  <p>My purpose is to make a data frame in which I can later input column 2 (cyl), either column 8 or 9 value (0 or 1), in order to get a value for column 1 (mpg)</p>
  
  <p>I want to rank mtcars by cyl, then by type, in order to end up with an organized data frame for mpg, in order to later find the highest mpg, depending on the input</p>
  
  <pre><code>ranking &lt;- mtcars[order(cyl, type, mpg)]
  </code></pre>
  
  <p>I apologize in advance, I am still a beginner in R, and I might not be correct in all the terminology and I would appreciate any advice!</p>