title: Dynamically add column to xts object
body: <p>Adding a column to an xts object is straightforward if you know the name of the column ahead of time.  For example, to add a column named "b":</p>
  
  <pre><code>n &lt;- 5
  x &lt;- merge(xts(order.by = as.Date('2015-1-1') + 1:n), a = rnorm(n))
  x$b &lt;- rnorm(n)
  </code></pre>
  
  <p>Adding a dynamically-named column (i.e., a column whose name is known only at runtime) is harder:</p>
  
  <pre><code>new.col.name &lt;- 'c' # known only at runtime
  x[, new.col.name] &lt;- rnorm(n) # this generates an error
  </code></pre>
  
  <p>One approach is to add a column with a temporary name and then rename it:</p>
  
  <pre><code>stopifnot(!('tmp' %in% names(x)))
  x$tmp &lt;- rnorm(n)
  names(x)[names(x) == 'tmp'] &lt;- new.col.name
  </code></pre>
  
  <p>Is there a better way to do this?  (Also, does assigning to <code>names</code> of an xts object result in a copy of the object being made?  So, for example, would the above approach work well if <code>n</code> were very large?)</p>