首页 > 解决方案 > 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

我正在尝试加入 2 个数据框,以便我拥有一个组合数据框,其中包含季节性假人和其他列。(想结合 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" 

标签: r

解决方案


下面的功能完成工作

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

推荐阅读