绑定无法按预期的时间序列对象R

问题描述 投票:0回答:1

原始数据集

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" 
r
1个回答
0
投票

以下功能完成工作

cbind(as.data.frame(test_data1), as.data.frame(dummy_test))
© www.soinside.com 2019 - 2024. All rights reserved.