[R] Store vectors as values in xts time-series object

Sergey Pisarenko drseergio at gmail.com
Sun Mar 4 11:23:32 CET 2012

Hi R programmers,

I have stumbled across what seems a very simple problem. My goal is to
create a xts time series object which contains vectors as values. In
other words, I try to create something like this:

2009-01-01 => c('aa', 'bb', 'dd')
2010-02-01 => c('mm')

I have figured out parts of separately. Here's what works (new xts
time-series with simple FALSE values):

> getSymbols(src='yahoo', Symbols=c('SPY'))           # this loads xts object into global environment under name SPY
> v <- vector(length=length(index(SPY)))                   # this creates a vector of the same length as the SPY time-series
> new_xts <- xts(v, order.by=index(SPY))                 # this works and creates a time-series with FALSE as every value
> new_xts
2009-01-01 FALSE
2010-02-01 FALSE

Now, I'd like to create a xts object with vectors as values.
Presumably, I want lists to be used as values:

> myList <- vector("list", length=length(index(SPY)))  # this creates a list of the same length as the SPY time-series
> for (i in 1:length(myList)) myList[[i]] <- c('aa', 'bb')    # fill list with dummy test data
> new_xts_2 <- xts(myList, order.by=index(SPY))      # and I get an error
Error in coredata.xts(x) : currently unsupported data type

What am I doing wrong and how can this be implemented?

Truly appreciate your effort.

Kind Regards,
Sergey Pisarenko.

More information about the R-help mailing list