title: How to use grep function to separate multiple column with common name in R?
body: <p>For the following data set, I would like to separate columns with <code>beta1</code> only.   </p>
  
  <pre><code>mydata
           beta1_C1 beta2_C2 beta1_C2 beta2_C1 beta3_C1 beta4_C2 beta4_C1 beta21_C1 beta21_C2 beta10_C1
      [1,]        1        9       17       25       33       41       49        57        65        73
      [2,]        2       10       18       26       34       42       50        58        66        74
      [3,]        3       11       19       27       35       43       51        59        67        75
      [4,]        4       12       20       28       36       44       52        60        68        76
      [5,]        5       13       21       29       37       45       53        61        69        77
      [6,]        6       14       22       30       38       46       54        62        70        78
      [7,]        7       15       23       31       39       47       55        63        71        79
      [8,]        8       16       24       32       40       48       56        64        72        80
  </code></pre>
  
  <p>I am using the following code but <code>beta10</code> is showing in the output which I do not want. In my expected data, I should have only <code>beta1_C1</code> and <code>beta1_C2</code> columns.</p>
  
  <pre><code> dat1=mydata[,grep("beta1",colnames(mydata))]
   dat1
           beta1_C1 beta1_C2 beta10_C1
      [1,]        1       17        73
      [2,]        2       18        74
      [3,]        3       19        75
      [4,]        4       20        76
      [5,]        5       21        77
      [6,]        6       22        78
      [7,]        7       23        79
      [8,]        8       24        80
  </code></pre>
  
  <p>Any help is appreciated.</p>