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

Joshua Ulrich josh.m.ulrich at gmail.com
Sun Mar 4 15:36:34 CET 2012


Hi Sergey,

Internally, xts objects are a matrix with an index attribute.  While
you *can* make a matrix of lists, that is not supported in zoo or xts.

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

R/Finance 2012: Applied Finance with R
www.RinFinance.com



On Sun, Mar 4, 2012 at 4:23 AM, Sergey Pisarenko <drseergio at gmail.com> wrote:
> 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 somethingSergey 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.
>
> ______________________________________________
> 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.



More information about the R-help mailing list