title: Subset character vector by pattern
body: <p>I have a character vector made up of filenames like: </p>
  
  <pre><code>vector &lt;- c("LR1_0001_a", "LR1_0002_b", "LR02_0001_b", "LR02_0002_x", "LR3_001_c") 
  </code></pre>
  
  <p>My goal is to subset this vector based on pattern matching the first x number of characters (dynamically), up to the first "_". The outputs would look something like this:</p>
  
  <pre><code>solution1 &lt;- c("LR1_0001_a", "LR1_0002_b")
  solution2 &lt;- c("LR02_0001_b", "LR02_0002_b")
  solution3 &lt;- c("LR3_001_c")
  </code></pre>
  
  <p>I have experimented with mixtures of <code>unique</code> and <code>grep</code> but have not had any luck so far</p>