title: check tables exceeding certain values and count number of times exceed respective threshold by respective id and label
body: <p>I have a dataframe df</p>
  
  <pre><code>df &lt;- data.frame(id =c(1,2,1,4,1,5,6),
                      label=c("a","b", "a", "a","a", "e", "a"), 
                      color = c("g","a","g","g","a","a","a"),
                      threshold = c(12, 10, 12, 12, 12, 35, 40),
                      value =c(32.1,0,15.0,10,1,50,45),stringsAsFactors = F
              )
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Zrziu.png" alt="enter image description here"></p>
  
  <p>Threshold value is based on the label</p>
  
  <p>I should get a table below like this by considering each id,with respective label how many times exceeding its threshold by the value</p>
  
  <p>Color is independent in consideration for calculating the exceed values </p>
  
  <p><img src="https://i.stack.imgur.com/a5c3L.png" alt="enter image description here"></p>
  
  <p>I tried like this </p>
  
  <pre><code>final_df &lt;- df %&gt;% 
    mutate(check = if_else(value &gt; threshold, 1, 0)) %&gt;% 
    group_by(id, label) %&gt;% 
    summarise(exceed = sum(check))
  </code></pre>
  
  <p>But instead of getting with respective id i have got the number of total in exceed</p>
  
  <p><img src="https://i.stack.imgur.com/e2RWr.png" alt="enter image description here"></p>