title: Order based on multiple columns passed in as an input
body: <p>I would like to write a function that sorts a given data.frame (which I'll refer to as dataSet) by any number of its columns, whose names are also passed into the function (in a vector which I will refer to as orderList). I know that to order by a single passed in string you can just use</p>
  
  <pre><code>sortDataset &lt;- function(dataSet, sortCol) {
  return(dataSet[order(dataSet[[sortCol]]),])
  }
  </code></pre>
  
  <p>and that you can order by multiple passed in strings using</p>
  
  <pre><code>sortDataset &lt;- function(dataSet, sortCol1, sortCol2) {
  return(dataSet[order(dataSet[[sortCol1]], dataSet[[sortCol2]]),])
  }
  </code></pre>
  
  <p>with however many sortCol# inputs as I would want. I would, however, like to be able to pass in a list of any number of strings. I tried the following:</p>
  
  <pre><code>dataSet[order(dataSet[[orderList]]),]
  dataSet[order(dataSet$orderList),]
  dataSet[order(dataSet[,orderList])]
  </code></pre>
  
  <p>and encountered issues that with the first 2, since they're just not a valid way to get multiple columns (I still tried, though ): ) and that in the third, order doesn't seem to accept the matrix returned by dataSet[,orderList] as a parameter.</p>
  
  <p>I would like a function as follows:</p>
  
  <pre><code>sortDataset &lt;- function(dataSet, sortCols)
  </code></pre>
  
  <p>where the first element of sortCols is the column which takes highest priority, then the second column is the first tiebreaker, the third column is the second tiebreaker, etc. and the function returns dataSet sorted appropriately. It would also be nice if I could specify whether each should be ascending in an optional input, so the first column could be sorting ascending, the second sorted descending, etc.</p>
  
  <p>So far, the only method I can really think of is to assume each list only contains numeric values, and then do some multiplying of the various sorting columns by 10^n so that all the columns can be consolidated into one column that maintains the priorities, and then sort by that column. I feel like there should be a better way to do this, though, since this seems like a pretty basic function.</p>