title: Why do I get an "Object not found" error when using group_by and summarise() in r?
body: <p>I'm trying to create a data frame containing the number of shootings by state and race by using group_by and summarise, however I keep getting an "object not found" error referring to the column names I've included, even though they exist.</p>
  
  <p>I've already tried restarting my session, restarting R, searching for answers by Googling, looking at related videos on YouTube including tutorials on group_by and summarise, and searching here on Stack Overflow and can't find anything that helps.</p>
  
  <p>The version of RStudio I'm using is: Version 1.1.463</p>
  
  <p>The code I've written that runs successfully is:</p>
  
  <pre><code>temp1 &lt;- cleansed_data[, c("state", "race", "for_count")]
  
  View(temp1)
  </code></pre>
  
  <p>The code that generates an error is:</p>
  
  <pre><code>temp2 &lt;- temp1 %&gt;% select(state, race, for_count) %&gt;% group_by(state, race) %&gt;% summarise(num_shootings = sum(for_count))
  </code></pre>
  
  <p>The error I see is:</p>
  
  <pre><code>Error in summarise(num_shootings = sum(for_count)) : 
    object 'for_count' not found
  </code></pre>
  
  <p>I'm expecting to get a 3 column data frame with columns state, race and num_shootings, with each row containing the sum of the for_count values for each combination of state and race.</p>
  
  <p>But I just get the "object not found" error.</p>
  
  <p>Additional info that my be useful is:</p>
  
  <p>The output of: </p>
  
  <pre><code>dput(head(temp1))
  </code></pre>
  
  <p>is: </p>
  
  <p>structure(list(state = c("IL", "PA", "FL", "IL", "CA", "PA"), race = c("Black", "White", "White", "Latino", "Unknown", "White"), for_count = c(1, 1, 1, 1, 1, 1)), row.names = c(NA, 6L), class = "data.frame")</p>
  
  <p>The libraries I have loaded are: </p>
  
  <p>tidyverse, operators, dplyr, ggplot2, knitr</p>
  
  <p>I'm trying to create an RMarkdown HTML file.</p>
  
  <p>The full RMarkdown file that this problem code is in is here: </p>
  
  <p><a href="https://github.com/foxnic/US-Mass-Shootings-Analysis/blob/master/Shootings_html_version.Rmd" rel="nofollow noreferrer">https://github.com/foxnic/US-Mass-Shootings-Analysis/blob/master/Shootings_html_version.Rmd</a></p>
  
  <p>...under:</p>
  
  <pre><code>## State &amp; Race
  </code></pre>