title: Force rows to get a certain value on a dummy
body: <p>I have a dataframe (lmr_sak) with verdicts from criminal cases in the Norwegian Court of Appeals from 1993-2019. On the 1st of October in 2015 a new criminal law (Straffeloven 2005 [not a typo, it took 10 years to come in to force]) replaced the old one from 1902.</p>
  <p>I want to create a dummy for whether a verdict utilized the old or new law. First, I created a dummy based on the dates:</p>
  <pre><code>lmr_sak$dato &lt;- as.Date.factor(lmr_sak$dato)
  
  
  lmr_sak &lt;- lmr_sak %&gt;% 
    mutate(strl1902 = ifelse(dato &gt; &quot;1993-01-04&quot; &amp; dato &lt; &quot;2015-10-01&quot;,1,0))
  </code></pre>
  <p>But the problem is that some of the verdicts after 2015-10-01 still used the old law (because the alleged crimes were committed before 2015-10-01), resulting in verdicts getting the wrong values on 'strl1902'.</p>
  <p>Luckily, in my df I have a column 'paragraf' which I think can help remedy the problem. Examples of its contents are:</p>
  <ul>
  <li>'Straffeloven (1902) §99'</li>
  <li>'Straffeloven (2005) §93'</li>
  <li>'Straffeloven 1902 §9'</li>
  <li>'Straffeloven 2005 §77'</li>
  </ul>
  <p>What I wish to do is to force the rows with the strings (1902) or 1902 to get 1 on 'strl1902', and rows with (2005) or 2005 to get 0.</p>
  <p>I imagine that I can do it with piping the code above, and maybe use ifelse(), replace() and a form of regex, but I'm very uncertain of what to do...</p>
  <p>ANSWER:</p>
  <p>Thanks to @Skaqqs suggestion, this ifelse with multiple logic did the trick:</p>
  <pre><code>lmr_sak_match$strl1902 = ifelse(lmr_sak_match$dato &gt; &quot;1993-01-04&quot; &amp; lmr_sak_match$dato &lt; &quot;2015-10-01&quot;, 1,
                                  ifelse(grepl(&quot;1902&quot;, lmr_sak_match$paragraf),1,0))
  </code></pre>