title: How to extract columns with same name but different identifiers in R
body: <p>Sorry if it is too basic, but I am not familiar with R.</p>
  
  <p>I have a data frame with multiple columns having the same column names, so after being imported to R, identifiers have been added. Something like this:</p>
  
  <pre><code>A = c(2, 3, 5)
  A.1 = c('aa', 'bb', 'cc')
  A.2 = c(TRUE, FALSE, TRUE) 
  B = c(1, 2, 5)
  B.1 = c('bb', 'cc', 'dd')
  B.2 = c(TRUE, TRUE, TRUE) 
  
  df = data.frame(A, A.1, A.2, B, B.1, B.2) 
  
  df
    A A.1   A.2 B  B.1   B.2
  1 2  aa  TRUE 1   bb  TRUE
  2 3  bb FALSE 2   cc  TRUE
  3 5  cc  TRUE 5   dd  TRUE
  </code></pre>
  
  <p>I would like to extract all columns that have <code>A</code>, regardless of the identifier extension so it becomes like:</p>
  
  <pre><code>  A A.1   A.2 
  1 2  aa  TRUE 
  2 3  bb FALSE 
  3 5  cc  TRUE 
  </code></pre>
  
  <p>I know we can </p>
  
  <pre><code>df2 = df[, c("A", "A.1", "A.2")]
  </code></pre>
  
  <p>But I have many of this type of columns so I do not want to type in individually. I am sure there are smart ways to do this.</p>
  
  <p>Thanks!</p>