title: counting the number of times a value appears in a column in relation to other columns in r
body: <p>I am new to r and I have a dataframe very close to the one below and I would love to find a general way that tells me how many times plus 1, the number "0" appears for each country (intro4) and id.   </p>
  
  <pre><code>        Intro4    number  id
    221    TAN           0  19
    222    TAN           0  73
    223    TAN           0  73
    224    TOG           0  37
    225    TOG           0  58
    226    UGA           0  96
    227    UGA           0 112
    228    UGA           0  96
    229    ZAM           0  40
    230    ZAM           0  99
    231    ZAM           0 139
  </code></pre>
  
  <p>I can do it by hand by it is a big data frame and would take forever, count () gives me the frequency but doesn't divide it between different countries. I have found a way to do it but I will have to select and filter for each individual county (intro4) and add 1 to the result. I was wondering if there was any quicker way to fo it. The code I have tried was this one: </p>
  
  <pre><code>projects &lt;- finalr %&gt;% select (Intro4,number,id)
  
  projects1&lt;-projects %&gt;%  filter (str_detect (number, "0"))
  
  projects2&lt;-projects1 %&gt;%arrange (Intro4)
  
  projects3&lt;-sum(projects2$Intro4 == "TAN", na.rm = TRUE)
  
  projects4&lt;-sum(projects2$Intro4=="UGA",na.rm=TRUE)
  </code></pre>
  
  <p>I would be extremely grateful for any help, thank you :)</p>