Cbind未按预期工作时间序列对象R



原始数据集

test_data1
Date Quantity Discount Segment Ship_Mode
1  2018-02-01      345     5000      20        20
2  2018-03-01      500      300      50        20
3  2018-04-01      400      400      40        30
4  2018-05-01      200      400     100        20

现在,我为季节性创建了名为dummy_test 的假人

dummy_test<- seasonaldummy(test_data1)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov
[1,]   0   1   0   0   0   0   0   0   0   0   0
[2,]   0   0   1   0   0   0   0   0   0   0   0
[3,]   0   0   0   1   0   0   0   0   0   0   0
[4,]   0   0   0   0   1   0   0   0   0   0   0

我试图将这两个数据帧连接起来,这样我就有了一个组合的数据帧,它既有季节性伪数据,也有其他列。(想要组合test_data1 的第2-4列

cbind(dummy_test,test_data1[,c(2:4)])
Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = FALSE, union = TRUE) : 
non-time series not of the correct length

结构

sapply(test_data1,class)
Quantity  Discount   Segment Ship_Mode 
"ts"      "ts"      "ts"      "ts" 

下面的函数完成的工作

cbind(as.data.frame(test_data1), as.data.frame(dummy_test))

最新更新