title: An R tidyverse way to select columns in order based on data type
body: <pre class="lang-r prettyprint-override"><code> library(tidyverse)
   #&gt; Warning: package 'tidyverse' was built under R version 3.4.4
   #&gt; Warning: package 'forcats' was built under R version 3.4.4
  
   example &lt;- tibble(
       num1 = sample(1:100, 10),
       categ1 = as.factor(c(sample(letters, 10))),
       num2 = sample(1:100, 10),
       categ2 = as.factor(c(sample(letters, 10)))
   )
  
   head(example)
   #&gt; # A tibble: 6 x 4
   #&gt;    num1 categ1  num2 categ2
   #&gt;   &lt;int&gt; &lt;fct&gt;  &lt;int&gt; &lt;fct&gt; 
   #&gt; 1     4 c          5 l     
   #&gt; 2    86 u         64 b     
   #&gt; 3    38 z         18 r     
   #&gt; 4    95 e         44 j     
   #&gt; 5    77 w         35 u     
   #&gt; 6    84 y         14 i
  </code></pre>
  
  <p>Created on 2018-06-19 by the <a href="http://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.2.0).</p>
  
  <p>The above example shows a basic dataframe with integer and factor data type columns. In this small example, it is easy to use the <code>select(example, categ1, categ2, num1, num2)</code> in <strong>dplyr</strong> to manually pick the order you want columns to appear. </p>
  
  <p>But suppose you have many columns that are a mixture of data types, and that you want all of the factors to be selected first followed by everything else (or any particular order based on data type)? </p>
  
  <p>Manually typing out each column name or using <code>select()</code> helpers like <code>contains()</code> can become tedious quickly with an innumerable amount columns. I prefer a <strong>tidyverse</strong> solution, but would also be interested how this could be accomplished in base R.</p>