[R-SIG-Finance] Naming conventions for merged XTS columns
jeff.a.ryan at gmail.com
Wed Oct 10 03:08:09 CEST 2012
I'm not in front of the relevant bits of code, but it would likely be in make.unique.names or something like that within merge.xts at the R level.
That said, relied upon seems unwise. The pattern is meant to match zoo behavior which in turn is meant to match matrix IIRC. But inconsistencies at the R level are pretty common around the edges, so xts matches "inconsistent" behavior to be most correct :-)
It very much depends on what the colnames are (defined, unique, etc) on the incoming objects and the order of the calls. Even as far as merge() vs merge.xts() vs cbind() vs cbind.xts() vs do.call(merge vs do.call(merge.xts. ...
You get the idea. Plus there are very real performance issues when trying to match native R or zoo behaviors in all cases.
Best to use colnames explicitly would be my advice.
Jeffrey Ryan | Founder | jeffrey.ryan at lemnica.com
On Oct 9, 2012, at 7:52 PM, Worik Stanton <worik.stanton at gmail.com> wrote:
> When I merge two xts with the same column names a '.1' is appended...
> Where does this convention come from and can it be firmly relied on?
> Sorry if this is a general 'R' question... But merge acts differently
> for data.frames
>> M <- xts(trunc(3*runif(3)), seq(as.Date(1), as.Date(3), by=1))
> 1970-01-02 0
> 1970-01-03 2
> 1970-01-04 1
>> colnames(M) <- 'a'
>> N <- xts(trunc(3*runif(3)), seq(as.Date(1), as.Date(3), by=1))
>> colnames(N) <- 'a'
> a a.1
> 1970-01-02 2 0
> 1970-01-03 1 2
> 1970-01-04 2 1
>> merge(as.data.frame(M), as.data.frame(N) )
> 1 1
> 2 2
> 3 2
> it does not matter I think that I shall never see
> how much I dig and dig A billboard lovely as a tree
> this hole just Indeed, unless the billboards fall
> keeps getting deeper I'll never see a tree at all
> R-SIG-Finance at r-project.org mailing list
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance