Re: [R] pass character vector in instrument field of get.hist.quote function

From: algotr8der <>
Date: Wed, 06 Apr 2011 09:06:59 -0700 (PDT)

Hi Joshua,

THank you for showing me how to use getSymbols. I am trying to follow the example you provided. However I am having some difficulty using the various combination of functions you have used. I tried to execute one step at a time as follows -

I have a ticker vector that looks like the following:

> tickers
 [1] "SPY" "DIA" "IWM" "SMH" "OIH" "XLY" "XLP" "XLE" "XLI" "XLB" "XLK" "XLU" "XLV"
[14] "QQQ"

> str(tickers)
 chr [1:14] "SPY" "DIA" "IWM" "SMH" "OIH" "XLY" "XLP" "XLE" ...

I wrote a function called myX to use in the lapply call. It has the following code:

myX <- function(tickers, start, end) {
getSymbols(tickers, from=start, to=end)

  1. Call lapply by itself

>lapply(tickers,myX,start="2001-03-01", end="2011-03-11")

> lapply(tickers,myX,start="2001-03-01", end="2011-03-11")
[1] "SPY"

[1] "DIA"

[1] "IWM"

[1] "SMH"

[1] "OIH"

[1] "XLY"

[1] "XLP"

[1] "XLE"

[1] "XLI"

[1] "XLB"

[1] "XLK"

[1] "XLU"

[1] "XLV"

[1] "QQQ"
So this works fine and I can inspect the value of any of the tickers i.e. SPY. Now I want to extract the Closing prices.

2) I did Cl(SPY) and this outputs the data in the Close column as expected. However, I am not sure how to extract the Closing prices of each of the elements inside the data structure returned by lapply, which I believe is a list structure. I want to merge them into one object as you did but I cant seem to follow.

Any guidance would be greatly appreciated.

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 06 Apr 2011 - 20:32:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 02:10:28 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive