title: R convert string to variable
body: <p>I'm using the <a href="http://www.quantmod.com/" rel="nofollow">quantmod</a> package in <code>R</code> to pull historical data from yahoo finance.</p>
  
  <p>To use the package I create a list of tickers like so:</p>
  
  <pre><code>symbols &lt;- c("MSFT", "ORCL", "AAPL", "FB")
  </code></pre>
  
  <p>To get the historical data I call the quantlib method getSymbols:</p>
  
  <pre><code>try(getSymbols(sym, src="yahoo"))
  </code></pre>
  
  <p>This creates variables in my environment called <code>MSFT</code>, <code>ORCL</code>, <code>APPL</code> and <code>FB</code>.</p>
  
  <p>To calculate a correlation between MSFT and ORCL with closing prices I can use</p>
  
  <pre><code>cor(Cl(MSFT), Cl(ORCL))
  </code></pre>
  
  <p>To get:</p>
  
  <pre><code>           ORCL.Close
  MSFT.Close  0.6597159
  </code></pre>
  
  <p>How can I make this generic so that i can pull say 20 symbols and run the correlation between them?</p>
  
  <p>I don't know how to refer to a variable given a string. ie I have the string "MFST", how do I refer to the variable <code>MSFT</code> ?</p>
  
  <p>I've got the string "MFST" and "ORCL" how can I use that to write <code>cor(Cl(MSFT), Cl(ORCL))</code></p>