[R-SIG-Finance] timeSeries:: bizarre rbind behavior with colnames

Jeff Ryan jeff.a.ryan at gmail.com
Tue Sep 29 16:46:35 CEST 2009


Hi Diethelm,

My comment was to use xts or zoo IN PLACE of "MATRIX", solely to
simplify the rbind process as the user and myself understood it.
Simply a safer solution than allowing a matrix rbind (not time aware).

timeSeries -> xts/zoo -> timeSeries is a better alternative than:

timeSeries -> matrix -> timeSeries

Aside from that, I think the expectation that rbind would work as it
does on matrix object, from which timeSeries is derived if I am
correct, isn't outside the realm of reason.

> m <- matrix(1:3)
> colnames(m) <- "Level"
> rbind(m,m)
     Level
[1,]     1
[2,]     2
[3,]     3
[4,]     1
[5,]     2
[6,]     3

Of course I wholeheartedly agree that documentation is important, and
should always be consulted before posted questions to the list and/or
maintainer.  That said:


?merge.timeSeries

Bind two timeSeries objects

Description:

     Binds two 'timeSeries' objects either by column or row.

Value:

     returns a S4 object of class 'timedate'.

Examples:

     ## data -
        x = as.timeSeries(data(msft.dat))[1:12, ]

     ## cbind -
        x1 <- cbind(x[, "Open"], returns(x[, "Open"]))
        colnames(x1) <- c("Open", "Return")

     ## rbind -
        rbind(x[1:3, "Open"], x[10:12, "Open"])

Isn't incredibly informative.

Best,
Jeff


On Sun, Sep 27, 2009 at 8:24 AM, Diethelm Wuertz
<wuertz at itp.phys.ethz.ch> wrote:
> Jeff Ryan wrote:
>>
>> Nicolas,
>>
>> I don't think this is a list question per se, as you should really
>> contact the maintainer.
>>
>> While I'll agree the design is odd, if you're insisting on using
>> timeSeries, and you find a problem, it would be more useful to all if
>> you proposed a patch.
>>
>> Complaints/demands for explanations/etc aren't productive, and
>> effectively show no consideration for the time and effort that
>> _contributors_ make to R.
>>
>
> *****************
>>
>> If you're looking for a better time-series solution than a matrix as
>> an interim representation, I would suggest xts.  Or zoo...
>>
>
> Dear Jeff,
>
> I don't like to comment this sentence (and also not the previous ones
> before).
>
> Documentation is written to be read!  The users can
> have a look into the free FAQ eBook:
>
> "A Discussion of Time Series Objects for R in Finance"
>
> Download it for free from
>
> --- http://www.rmetrics.org/ebook.htm ---
>
> There you will find also information on the usage of c,
> cbind, rbind, and merge, and how these functions work
> and how they should be used.
>
> In this eBook many frequently asked questions are answered
> on an objective level. Everybody is invited to contribute to
> this eBook and to improve its content. Suggestions are
> welcome.
>
>
> Diethelm
>
>
> **********************
>>
>> Jeff
>>
>> On Wed, Sep 23, 2009 at 10:43 AM, Nicolas Chapados
>> <nicolas.chapados at gmail.com> wrote:
>>
>>>
>>> Dear list,
>>>
>>> Looking at the code for timeSeries::rbind, it appears that it insists
>>> on concatenating the names of the two series it's trying to bind, even
>>> if they match exactly, thereby creating a longer series name.  This is
>>> in sharp contrast to, e.g. rbind.data.frame.  This creates very
>>> badly-behaved column names (i.e. horrendously-long) in the case where
>>> one attempts to construct a timeSeries incrementally.
>>>
>>> For example:
>>>
>>>
>>>>
>>>> rbind(timeSeries(1.0, timeDate("1996-01-01"), units="Level"),
>>>> timeSeries(2.0, timeDate("2009-01-01"), units="Level"))
>>>>
>>>
>>> GMT
>>>          Level_Level
>>> 1996-01-01           1
>>> 2009-01-01           2
>>>
>>>
>>> Can someone explain the design rationale for choosing to concatenate
>>> the column names in such a manner?  In the short term, I resolved to
>>> incrementally constructing a matrix, and at the very end building a
>>> timeSeries, but I would really prefer to keep timeSeries all along...
>>>
>>> Many thanks for any help!
>>> + Nicolas Chapados
>>>
>>> _______________________________________________
>>> R-SIG-Finance at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only.
>>> -- If you want to post, subscribe first.
>>>
>>>
>>
>>
>>
>>
>
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list