title: Using variable to call specific column in R?
body: <p>I would like to use a character vector object to easily extract column data from an xts object. I simply tried to assign the first column name to a variable <code>x</code> and call it by using <code>mx$x</code>, but it is no use. Is there any way to do this?</p>
  
  <pre><code>library(xts)
  mx &lt;- xts(rnorm(10), Sys.Date()+1:10)
  colnames(mx) &lt;- "good"
  x &lt;- "good"
  mx$x
  # NULL
  mx[x]
  # Error in if (length(c(year, month, day, hour, min, sec)) == 6 &amp;&amp; c(year,  : 
  # missing value where TRUE/FALSE needed
  # In addition: Warning messages:
  # 1: In as_numeric(YYYY) : NAs introduced by coercion
  # 2: In as_numeric(YYYY) : NAs introduced by coercion
  mx[[x]]
  # Error in mx[[x]] : subscript out of bounds
  </code></pre>