title: find last row with to multiple groups
body: <pre><code>| id | msgid | source | value |
  |----|-------|--------|-------|
  | 1  | 1     | B      | 0     |
  | 1  | 2     | A      | 1     |
  | 1  | 3     | B      | 0     |
  | 2  | 1     | B      | 0     |
  | 2  | 2     | A      | 0     |
  | 2  | 3     | A      | 1     |
  | 2  | 4     | B      | 0     |
  </code></pre>
  
  <p>In the above snippet, I want to create column <code>value</code> from the other columns. <code>id</code> is a conversation and <code>msgId</code> is the message in each conversation. </p>
  
  <p>I wish to identify the row number for the last message that came from <code>source=A</code>. </p>
  
  <p>I made an attempt to solve it. However, I was able to identify only the last row within a conversation. </p>
  
  <pre><code>last_values &lt;- dat %&gt;% group_by(id) %&gt;% 
     slice(which.max(msgid)) %&gt;%
     ungroup %&gt;%
     mutate(value = cumsum(msgid))
  
  dat$final_val &lt;- 0    
  dat[last_values$value,5] &lt;- 1
  </code></pre>