title: R: Calculate percentage of activities with "Gloves". Ie. count as TRUE if "Gloves" exists for each ID
body: <p>I have a data frame df with a series of surfaces that are touched during particular activities (coded 1 to 5).</p>
  
  <pre><code>df&lt;-tibble(Surface=sample(c("Gloves","foo","bar","AlcoholGel","Sink"),50,replace = TRUE),ActivityID=rep(1:5,each=10))
  </code></pre>
  
  <p>I would like to calculate the percentage of activities (<code>ActivityID</code>) that have at least 1 occurrence of "Gloves".</p>
  
  <p>I'm trying the following <code>dplyr</code> code but it over-counts because there might be more than 1 instance in "Gloves" in each ActivityID. Any thoughts would be much appreciated.</p>
  
  <pre><code>require(dplyr)
      df%&gt;%
        group_by(ActivityID)%&gt;%
        summarise(sum(match(Surface,"Gloves"),na.rm = TRUE))
  </code></pre>
  
  <p>I'd like to see a summary table of activities that have Gloves in their list of surface (if calculating the percentage in one go is not so easy.</p>