title: How do i programatically select columns to mutate?
body: <p>Example data:</p>
  
  <pre><code>Project  2016   2017   2018   2019
  Proj1      42     36    400    250
  Proj2      96    780     60    900
  Proj3     180    230      0      0
  </code></pre>
  
  <p>I have a set of financial data from this year, that comes with previous years' financial data as well.  I am trying to mutate the data so that I add the previous three years into a "Previous Funding" column.</p>
  
  <p>The data has columns labeled with 2016, 2017, 2018, 2019... etc</p>
  
  <pre><code>Totals&lt;-Totals %&gt;% mutate("Previous Years"=`2016`+`2017`+`2018`)
  </code></pre>
  
  <p>Now, I'm actually trying to set this up so that I can select this programmatically; next year, I'd rather look at 2017, 2018, and 2019 data, naturally, and I'd like to just set it up so that I can enter a year number, and it will select the right columns using code.</p>
  
  <pre><code>year = 2019
  
  index&lt;-which(colnames(Totals)==year)
  
  Totals&lt;-Totals%&gt;%
  ##Here's where it gets hairy
  mutate("Previous Years"=Totals[index-3]+Totals[index-2]+Totals[index-1])
  
  Error: Column `Previous Years` is of unsupported class data.frame
  </code></pre>
  
  <p>So, there are some issues.  Obviously, I'm calling something incorrectly, scenario 1 above works like a charm, and the second scenario gives an error.  I feel like it has something to do with the back ticks that you would normally use to call columns with unusual names in dplyr.</p>
  
  <p>What is the proper way to do something like this?</p>