首页 > 解决方案 > 使用 cbind 合并 xts 对象时 colnames 的行为

问题描述

如果我使用cbind合并两个matricesordata.frames具有相同colnames的那些colnames在新的matrixor中保持不变data.frame

df <- data.frame(test = c(1,2))
df.merge <- cbind(df,df)

df.merge
test test
1    1    1
2    2    2

但是,如果我对xts对象执行相同操作,则会将数值添加到colnames

df.xts <- xts(df, order.by = as.POSIXct(c("2019-02-18 13:00","2019-02-18 14:00"), tz = "UTC"))
df.xts.merge <- cbind(df.xts, df.xts)

df.xts.merge
                    test test.1
2019-02-18 13:00:00    1      1
2019-02-18 14:00:00    2      2

xts有没有办法通过合并对象来防止重命名列?

标签: rxtscbind

解决方案


推荐阅读