xts object – subscript out of bounds

February 6, 2013

(This article was first published on Copula, and kindly contributed to R-bloggers)

I bet you have seen this error a few times. When I compare large xts objects with different number of observations it would hit me right towards the end of the analysis.
I wrote a small function, which allows me to check the length of the sets in advance and retains only the symbols, which hold the exact number of observations required.
benchmark is simply my ticker with the number of observations I would like to see.

checkrow <- function(Tickers,Bench,From,To)
  getSymbols(Bench, index.class=”POSIXct”, from = From, to = To,src=”yahoo”)
  my = NA
  for(sticker in tickers){
    if( NROW(x)
    if( NROW(x)==m)
  my = my[-1]
  tickers = my

To leave a comment for the author, please follow the link and comment on their blog: Copula.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)