title: How to write a simple function to combine all these similar codes?
body: <p>There are hundreds of columns need to be cleaned in  the raw data. Each part of them is with the similar structure. For the analysis, I need to combine all the parts into a total one with the same colnames.</p>
  
  <p>However, I really don't know how to do it with both variables and characters. Should I use !! ?</p>
  
  <pre class="lang-r prettyprint-override"><code>Q14_1 &lt;- Q14 %&gt;% select(province, ends_with("open_1"))
  colnames(Q14_1) &lt;- c("province", paste0("A", 1:11))
  
  Q14_2 &lt;- Q14 %&gt;% select(province, ends_with("open_2"))
  colnames(Q14_2) &lt;- c("province", paste0("A", 1:11))
  
  Q14_3 &lt;- Q14 %&gt;% select(province, ends_with("open_3"))
  colnames(Q14_3) &lt;- c("province", paste0("A", 1:11))
  
  Q14_4 &lt;- Q14 %&gt;% select(province, ends_with("open_4"))
  colnames(Q14_4) &lt;- c("province", paste0("A", 1:11))
  
  Q14_bind &lt;-bind_rows(Q14_1, Q14_2, Q14_3, Q14_4)
  
  </code></pre>
  
  <p>Is there a simple way to address this issue?</p>
  
  <p>Thanks to Dr Parfait.</p>
  
  <h2>His code works!</h2>
  
  <pre class="lang-r prettyprint-override"><code>df_list &lt;- lapply(paste0("open_", 1:20), function(i) 
    setNames(select(Q14, province, ends_with(i)), 
             c("province", paste0("A", 1:11)))
  )
  </code></pre>
  
  <p>df_list %>% bind_rows()</p>