黄齐
2014-Jun-09 08:12 UTC
[R] how to get information of many stocks by using loop cycling in R
Dear R-core : I am a user of R language from China. I have some problems when I use function ¡°getSymbols¡± which belongs to package ¡°quantmod¡±,and I hope I can get some help from you. I can get some information of one stock just by entering ¡°s1<-getSymbols("600016.ss",from = "2011-05-01",to "2014-05-01",auto.assign=FALSE)¡±in the R workspace, but if I want to get some information of 100 stocks, it is inconvenient for me to enter similar order hundred times. So I want to use loop cycling. stock<-c("600016.ss","600059.ss","600060.ss","600069.ss") for(i in seq(stock)) { S[i]<-getSymbols(stock[i],from="2011-05-01",to="2014-05-01",auto.assign=FALS E) } But I do not know how to define S because the class of S[i] are ¡°xts¡± and ¡°zoo¡±. Could you give some help, thank you very much. One of users of R in China [[alternative HTML version deleted]]
William Dunlap
2014-Jun-09 14:40 UTC
[R] how to get information of many stocks by using loop cycling in R
Make 'S' either an environment or a list. E.g., SymList <- lapply(c("TIBX","X","IBM"), getSymbols, auto.assign=FALSE) # lapply returns a list or SymEnv <- new.env() # or SymList <- list() for(sym in c("TIBX", "X", "IBM")) SymEnv[[sym]] <- getSymbols(sym, auto.assign=FALSE) Use SymList[["TIBX"]] or SymEnv[["TIBX"]] to extract the information for TIBX. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jun 9, 2014 at 1:12 AM, ?? <m15972031039 at 163.com> wrote:> Dear R-core : > > I am a user of R language from China. I have some problems when I use > function ?getSymbols? which belongs to package ?quantmod?,and I hope I > can get some help from you. > > I can get some information of one stock just by entering > ?s1<-getSymbols("600016.ss",from = "2011-05-01",to > "2014-05-01",auto.assign=FALSE)?in the R workspace, but if I want to get > some information of 100 stocks, it is inconvenient for me to enter similar > order hundred times. So I want to use loop cycling. > > > > stock<-c("600016.ss","600059.ss","600060.ss","600069.ss") > > for(i in seq(stock)) > > { > > S[i]<-getSymbols(stock[i],from="2011-05-01",to="2014-05-01",auto.assign=FALS > E) > > } > > > > But I do not know how to define S because the class of S[i] are ?xts? and > ?zoo?. > > Could you give some help, thank you very much. > > > One of users of R in China > > > > > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >