title: Calculating percentage from dplyr's filter function in R
body: <p>I have the following data:</p>
  
  <pre><code>df &lt;- tibble(
    "result" = c("win", "loss", "win", "win", "loss", "win", "win", "loss"),
    "team" = c("TBL", "NJD", "TBL", "STL", "TBL", "STL", "NJD", "STL"),
  )
  </code></pre>
  
  <p>The table has two columns - <code>result</code> and <code>team</code>. I want to calculate the percentage that a team has "win" as the result. I used <code>dplyr</code> to do a quick count of each result, "win" or "loss" - </p>
  
  <pre><code>df_win &lt;- df %&gt;% 
    group_by(result, team) %&gt;% 
    filter(result == "win") %&gt;% 
    summarise(count = n())
  
  df_loss &lt;- df %&gt;% 
    group_by(result, team) %&gt;% 
    filter(result == "loss") %&gt;%
    summarise(count = n())
  </code></pre>
  
  <p>I want to use <code>mutate</code> to create a formula to calculate the number of times the team had a "win" (and conversely for "loss):</p>
  
  <pre><code>df %&gt;%
    mutate(team_win_perc = ((df_win / df_loss) * 0.1 )))
  </code></pre>
  
  <p>But obviously one can't just multiply two tables together without consequences: </p>
  
  <pre><code>Error in mutate_impl(.data, dots) : 
    Evaluation error: non-numeric argument to binary operator.
  </code></pre>
  
  <p>Asking as the moron I sometimes am, how do I format this?</p>