title: Swap rows in a data frame based on a criteria
body: <p>I have a data.table something like this. Here is the <code>dput</code> of it.</p>
  
  <pre><code>structure(list(Sepal.Length = c(5.4, 5.1, 5, 5, 4.9, 4.9, 4.7, 
  4.6, 4.6, 4.4, 5.4, 5.1, 5, 5, 4.9, 4.9, 4.7, 4.6, 4.6, 4.4), 
      Sepal.Width = c(3.9, 3.5, 3.6, 3.4, 3.1, 3, 3.2, 3.4, 3.1, 
      2.9, 3.9, 3.5, 3.6, 3.4, 3.1, 3, 3.2, 3.4, 3.1, 2.9), Petal.Length = c(1.7, 
      1.4, 1.4, 1.5, 1.5, 1.4, 1.3, 1.4, 1.5, 1.4, 1.7, 1.4, 1.4, 
      1.5, 1.5, 1.4, 1.3, 1.4, 1.5, 1.4), Petal.Width = c(0.4, 
      0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.3, 0.2, 0.2, 0.4, 0.2, 0.2, 
      0.2, 0.1, 0.2, 0.2, 0.3, 0.2, 0.2), Species = structure(c(1L, 
      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
      1L, 1L, 1L, 1L), .Label = c("setosa", "versicolor", "virginica"
      ), class = "factor"), order = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 
      8L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L)), .Names = c("Sepal.Length", 
  "Sepal.Width", "Petal.Length", "Petal.Width", "Species", "order"
  ), row.names = c(NA, -20L), class = c("data.table", "data.frame"
  ), .internal.selfref = &lt;pointer: 0x0000000000340788&gt;)
  </code></pre>
  
  <p>It looks like this. It is just a sample.</p>
  
  <pre><code>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species order
   1:          5.4         3.9          1.7         0.4  setosa     1
   2:          5.1         3.5          1.4         0.2  setosa     2
   3:          5.0         3.6          1.4         0.2  setosa     3
   4:          5.0         3.4          1.5         0.2  setosa     4
   5:          4.9         3.1          1.5         0.1  setosa     5
   6:          4.9         3.0          1.4         0.2  setosa     6
   7:          4.7         3.2          1.3         0.2  setosa     7
   8:          4.6         3.4          1.4         0.3  setosa     8
   9:          4.6         3.1          1.5         0.2  setosa     9
  10:          4.4         2.9          1.4         0.2  setosa    10
  11:          5.4         3.9          1.7         0.4  setosa     1
  12:          5.1         3.5          1.4         0.2  setosa     2
  13:          5.0         3.6          1.4         0.2  setosa     3
  14:          5.0         3.4          1.5         0.2  setosa     4
  15:          4.9         3.1          1.5         0.1  setosa     5
  16:          4.9         3.0          1.4         0.2  setosa     6
  17:          4.7         3.2          1.3         0.2  setosa     7
  18:          4.6         3.4          1.4         0.3  setosa     8
  19:          4.6         3.1          1.5         0.2  setosa     9
  20:          4.4         2.9          1.4         0.2  setosa    10
  </code></pre>
  
  <p>What I want is to swap those rows wherever column <code>order</code>'s value is 1 and 2 (keeping column <code>order</code> as is but swap the remaining columns). <strong>So, in the above table, row 1 will get swapped with row 2 and row 11 will get swapped with row 12.</strong></p>
  
  <p>So the output will look like:</p>
  
  <pre><code>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species order
   1:          5.1         3.5          1.4         0.2  setosa     1
   2:          5.4         3.9          1.7         0.4  setosa     2
   3:          5.0         3.6          1.4         0.2  setosa     3
   4:          5.0         3.4          1.5         0.2  setosa     4
   5:          4.9         3.1          1.5         0.1  setosa     5
   6:          4.9         3.0          1.4         0.2  setosa     6
   7:          4.7         3.2          1.3         0.2  setosa     7
   8:          4.6         3.4          1.4         0.3  setosa     8
   9:          4.6         3.1          1.5         0.2  setosa     9
  10:          4.4         2.9          1.4         0.2  setosa    10
  11:          5.1         3.5          1.4         0.2  setosa     1
  12:          5.4         3.9          1.7         0.4  setosa     2
  13:          5.0         3.6          1.4         0.2  setosa     3
  14:          5.0         3.4          1.5         0.2  setosa     4
  15:          4.9         3.1          1.5         0.1  setosa     5
  16:          4.9         3.0          1.4         0.2  setosa     6
  17:          4.7         3.2          1.3         0.2  setosa     7
  18:          4.6         3.4          1.4         0.3  setosa     8
  19:          4.6         3.1          1.5         0.2  setosa     9
  20:          4.4         2.9          1.4         0.2  setosa    10
  &gt; 
  </code></pre>
  
  <p>Please notice in the above output rows 1 and 2 and rows 11 and 12 of the original table have been swapped keeping column <code>order</code> as is. How do I do this in the most efficient manner i.e quickly without running any loop?</p>