r - 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"
解决方案
下面的功能完成工作
cbind(as.data.frame(test_data1), as.data.frame(dummy_test))
推荐阅读
- google-cloud-platform - 为什么在 csv 文件上传输 GCP 失败,错误日志在哪里?
- javascript - 如何使用 NodeJS 从 html 表单执行 PATCH 请求?
- java - 在运行时复制文件并使用不同的文件扩展名重命名
- javascript - 如何通过 Javascript 从 HTML 文件连接到 Sqlite 数据库
- react-native - 为移动和 Web 创建简单的 react-native 模块的问题
- python - 如何从列表中计算每组中的负数和正数?
- android - FCM:访问所有发送的推送消息
- javascript - 为什么空数组上的 findIndex 不返回 -1?
- node.js - 发送带有请求的json以在节点中表达
- kubernetes - containerPort 是端口中容器的端口还是端口本身?