title: Subset columns based on list of column names and bring the column before it
body: <p>I have a larger dataset following the same order, a unique date column, data, unique date column, date, etc. I am trying to subset not just the data column by name but the unique date column also. The code below selects columns based on a list of names, which is part of what I want but any ideas of how I can grab the column immediately before the subsetted column also?</p>
  
  <p>Looking to end up with a DF containing Date1, Fire, Date3, Earth columns (using just the NameList).</p>
  
  <p>Here is my reproducible code:</p>
  
  <pre><code>Cnames &lt;- c("Date1","Fire","Date2","Water","Date3","Earth")
  MAINDF &lt;- data.frame(replicate(6,runif(120,-0.03,0.03)))
  colnames(MAINDF) &lt;- Cnames
  
  NameList &lt;- c("Fire","Earth")
  
  NewDF &lt;- MAINDF[,colnames(MAINDF) %in% NameList] 
  </code></pre>