我有空的xts对象,我想用简单的计算填充列(predified date - xts index(date)/ 365)。我已经能够填补第一个问题,问题是我有46个,并在未来更多的专栏,所以我这样做的方式不是最佳的。这是我能做的。我如何填充4个(实际样本中的46个)的其余部分,而不必像本例中那样合并每一列。在R中填充空xts对象
创建空的XTS
xts <- xts(order.by=index(xts))
merge(xts, col1 = (dt[1] - index(xts))/365)
col1
2010-12-31 6.512329
2011-01-03 6.504110
2011-01-04 6.501370
2011-01-05 6.498630
2011-01-06 6.495890
2011-01-07 6.493151
最终的结果应该是这样的。
col1 col2 col3 col4 col5
2010-12-31 6.512329 6.789041 7.016438 7.153425 7.287671
2011-01-03 6.504110 6.780822 7.008219 7.145205 7.279452
2011-01-04 6.501370 6.778082 7.005479 7.142466 7.276712
2011-01-05 6.498630 6.775342 7.002740 7.139726 7.273973
2011-01-06 6.495890 6.772603 7.000000 7.136986 7.271233
2011-01-07 6.493151 6.769863 6.997260 7.134247 7.268493
这里是具有5个预定日期的dt变量的数据。
dput(xts)
structure(numeric(0), index = structure(c(1293753600, 1294012800,
1294099200, 1294185600, 1294272000, 1294358400), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC")
dput(dt)
structure(c(17351L, 17452L, 17535L, 17585L, 17634L), class = "Date")
感谢它的工作。 – Viitama