title: How can I change the name of a data frame
body: <p>I have a recurrent situation where I set a value at the top of a long set of R code that's used in subsetting one or more data frames.  Something like this:</p>
  
  <pre><code>city_code &lt;- "202"
  </code></pre>
  
  <p>At the end of the whole process I'd like to save the results in a data frame that's named appropriately, say, based on appending "city_code" to a  common stub.</p>
  
  <pre><code>city_results &lt;- paste("city_stats", city_code, sep = "")
  </code></pre>
  
  <p>My problem is that I can't figure out how to rename the resulting data frame as the value of 'city_results'.  Lots of info out there on how to rename the columns of a data frame, but not on how to rename the data frame itself.  Based on a proposed answer, here's a clarification:</p>
  
  <p>Thanks, @mike-wise.  Helpful to study Hadley's Advanced R with a concrete problem in hand.</p>
  
  <pre><code>library(dplyr)
  gear_code &lt;- 4
  gear_subset &lt;- paste("mtcars_", gear_code, sep = "")
  mtcars_subset &lt;- mtcars %&gt;% filter(gear == gear_code)
  head(mtcars_subset)
  write.csv(mtcars_subset, file = paste(gear_subset, ".csv", sep = ""))
  </code></pre>
  
  <p>That lets me write the subset to an appropriately named csv file.  However, your suggestion kind of works, but I can't, for example, reference the data.frame with the new name:</p>
  
  <pre><code>assign(gear_subset, mtcars_subset)
  head(gear_subset)
  </code></pre>