title: dplyr: Mutate column base on match string of column
body: <p>I have this dataframe ds:</p>
  
  <pre><code>sample
  16LM1DNA
  16M1DNA
  </code></pre>
  
  <p>And I would like to create a new column base on LM or M in the sample names:</p>
  
  <p>I have this code:</p>
  
  <pre><code>ds %&gt;% 
  mutate(group = case_when( 
  matches(sample, "\\d+LMd+") ~ "LM",
  matches(sample, "\\d+Md+") ~ "M"
  )) 
  </code></pre>
  
  <p>But it doesn't work.</p>
  
  <p>Best</p>