Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@PHXtrader what you are trying to do is to replace an element in a vector of characters with a xts object which is not what you want to do and does not make sense. To assign a value to a <em>name</em> you have to use the 'assign' function (<em>?assign</em> to get further information). The other error in your code is that you use 'as.xts' instead of only 'xts' . Have a look at this toy example:</p> <pre><code>tickers &lt;- c("AMZN","AAPL") # this is a character object getSymbols("SPY",from="2013-09-01") # this is a xts object for (i in 1:length(tickers)) { assign(tickers[i],xts(order.by = index(SPY))) } </code></pre> <p>the result are 2 xts objects, named AMZN and AAPL with zero-with.</p> <pre><code>&gt;str(AAPL) An 'xts' object of zero-width &gt; AAPL Data: numeric(0) Index: Date[1:9], format: "2013-09-03" "2013-09-04" "2013-09-05" "2013-09-06" "2013-09-09" ... </code></pre> <p>I think a better and safer way to accomplish what you want to do is by using a list ( or sometimes creating a new environment). Creating objects as above tends to lead to bugs that are very difficult to find and debug, these types of constructs lead to accidentally overwriting variables and many other potential errors. The following example avoids a loop and creates the empty objects in a list:</p> <pre><code>tickers &lt;- c("AMZN","AAPL") mylist &lt;- rep(as.list(xts(order.by = index(SPY))),2) # creates 2 empty xts-objects in list names(mylist) &lt;- tickers &gt; str(mylist) List of 2 $ AMZN:An 'xts' object of zero-width $ AAPL:An 'xts' object of zero-width </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload