title: Coercing List of List Individual Elements to Vector Type
body: <p>I'm using the permn function from CRAN package combinat to produce a list of lists composed of all the permutations of a range of numbers as follows</p>
  
  <pre><code>x &lt;- str(permn(3))
  x
  
  List of 6
  $ : int [1:3] 1 2 3
  $ : int [1:3] 1 3 2
  $ : int [1:3] 3 1 2
  $ : int [1:3] 3 2 1
  $ : int [1:3] 2 3 1
  $ : int [1:3] 2 1 3
  </code></pre>
  
  <p>I also have </p>
  
  <pre><code>typeof(x[[1]])
  "integer"
  </code></pre>
  
  <p>My goal is to sort this list of lists in ascending numerical order (each element needs to be treated as a three digit number), and while the following works correctly </p>
  
  <pre><code>permn(3)-&gt;x
  x[order(sapply(x,'[[',1))]
  [[1]]
  [1] 1 2 3
  
  [[2]]
  [1] 1 3 2
  ...
  </code></pre>
  
  <p>any permn(n) n>3 yields an incorrect sorting. I realize that my issue is that I am sorting on individual values rather than n digit numbers, but I can't figure out how to decompose, sort, and then recompose correctly. I've tried </p>
  
  <pre><code>function(n){
  out &lt;-list()
  permn(n)-&gt;list.of.lists
  for(i in 1:length(list.of.lists)){
  out[[length(out)+1]] &lt;- unlist(list.of.lists[i])
  }
  out
  </code></pre>
  
  <p>but it gives the same results as </p>
  
  <pre><code>x[order(sapply(x,'[[',1))]
  </code></pre>
  
  <p>namely, I don't have each element ordered in the context of the other elements I'm working with.</p>
  
  <p>Any suggestions?</p>