title: How to get all columns with the same column name in R at once?
body: <p>Let's say I have the following data frame:</p>
  
  <pre><code>&gt; test &lt;- cbind(test=c(1, 2, 3), test=c(1, 2, 3))
  &gt; test
       test test
  [1,]    1    1
  [2,]    2    2
  [3,]    3    3
  </code></pre>
  
  <p>Now from such data frame I want to fetch all the columns named "test" to a new data frame:</p>
  
  <pre><code>&gt; new_df &lt;- test[, "test"]
  </code></pre>
  
  <p>However this last attempt to do so only fetches the first column called "test" in test data frame:</p>
  
  <pre><code>&gt; new_df
  [1] 1 2 3
  </code></pre>
  
  <p>How can I get all of the columns called "test" in this example and put them into a new data frame in a single command? In my real data I have many columns with repeated colnames and I don't know the index of the columns so I can`t get them by number.</p>