title: Check if value of column A is present in the same row or previous rows of column B
body: <p>I have this dataframe:</p>
  <pre><code>df &lt;- structure(list(A = 1:5, B = c(1L, 5L, 2L, 3L, 3L)), 
                  class = &quot;data.frame&quot;, row.names = c(NA, -5L))
  
    A B
  1 1 1
  2 2 5
  3 3 2
  4 4 3
  5 5 3
  </code></pre>
  <p>I would like to get this result:</p>
  <pre><code>  A B Result
  1 1 1      B
  2 2 5   &lt;NA&gt;
  3 3 2   &lt;NA&gt;
  4 4 3   &lt;NA&gt;
  5 5 3      B
  </code></pre>
  <p>Strategy:</p>
  <ol>
  <li>Check if <code>A==B</code> then assign <code>B</code> to new column <code>Result</code> if not <code>NA</code>.</li>
  <li>But do this also for all <em><strong>PREVIOUS</strong></em> rows of <code>B</code>.</li>
  </ol>
  <p><strong>AIM:</strong></p>
  <p>I want to learn how to check if a certain value of column <code>A</code> say in row 5
  is in the previous rows of column <code>B</code> (eg. row 1-4).</p>