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

Diethelm Wuertz wuertz at itp.phys.ethz.ch
Sun Sep 27 15:40:36 CEST 2009

Nicolas Chapados 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.
NO, you don't have understood properly the functions c, cbind, rbind, 
and merge for timeSeries objects and data.frames !!!
> For example:
>> rbind(timeSeries(1.0, timeDate("1996-01-01"), units="Level"), timeSeries(2.0, timeDate("2009-01-01"), units="Level"))
>            Level_Level
> 1996-01-01           1
> 2009-01-01           2
That is exactly what you should get back, when you bind two univariate 
time series row by row. You bind two series with the same name and this 
is expressed by the column name Level_Level.

I think what you like to do is to merge the two time series and not to 
bind rowwise, or?

merge(timeSeries(1.0, timeDate("1996-01-01"), units="Level"), timeSeries(2.0, timeDate("2009-01-01"), units="Level"))

then you get:

1996-01-01     1
2009-01-01     2

what you possibly would have been expected! merge assumes that the source of the data is really exactly the same.

Look to all the other examples presented in the ebook concernd with the concatenation of time series:

"A Discussion of Time Series Objects for R in Finance"

Download it for free from

--- http://www.rmetrics.org/ebook.htm ---

to learn more about the usage of c, cbind, rbind, and merge.


> 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.

More information about the R-SIG-Finance mailing list