R语言学习-问题解决-Error in `[<-.ts`(`*tmp*`,...only replacement of elements is allowed
来源:互联网 发布:2016超级女声网络投票 编辑:程序博客网 时间:2024/05/23 02:15
在输出时间序列结果的时候,出现以下问题:
for (n in 0:99) { salesTS <-ts(src_dat$rate_m[(1+24*n):(24*n+24)],frequency=12,start=c(2015,1,1)) salesForecasts<- HoltWinters(salesTS) salesForecast2<- forecast:::forecast.HoltWinters(salesForecasts,h=12) output <- rbind(output,data.frame(prd_code=src_dat$prod_no[(1+24*n)],year="2017",month=seq(1:12),rate=salesForecast2$mean) ) } Error in `[<-.ts`(`*tmp*`, ri, value = c(2.7110254334953, 2.95418132827278, : only replacement of elements is allowed提示rbind的时候出错,分别查看rbind两端的数据
> output prd_code year month rate1 13213798874 2017 1 2.7110252 13213798874 2017 2 2.9541813 13213798874 2017 3 2.5614914 13213798874 2017 4 2.3138765 13213798874 2017 5 1.9488656 13213798874 2017 6 1.3296177 13213798874 2017 7 2.5506688 13213798874 2017 8 2.0891589 13213798874 2017 9 1.90907810 13213798874 2017 10 2.00629511 13213798874 2017 11 1.94180112 13213798874 2017 12 1.855000> tmp<-data.frame(prd_code=src_dat$prod_no[(1+24*n)],year="2017",month=seq(1:12),rate=salesForecast2$mean)> tmp prd_code year month rate1 13213818469 2017 1 2.7110252 13213818469 2017 2 2.9541813 13213818469 2017 3 2.5614914 13213818469 2017 4 2.3138765 13213818469 2017 5 1.9488656 13213818469 2017 6 1.3296177 13213818469 2017 7 2.5506688 13213818469 2017 8 2.0891589 13213818469 2017 9 1.90907810 13213818469 2017 10 2.00629511 13213818469 2017 11 1.94180112 13213818469 2017 12 1.855000显示并没有什么问题,那么分析下各个列的属性
> class(output)[1] "data.frame"> str(output)'data.frame':12 obs. of 4 variables: $ prd_code: num 1.32e+10 1.32e+10 1.32e+10 1.32e+10 1.32e+10 ... $ year : Factor w/ 1 level "2017": 1 1 1 1 1 1 1 1 1 1 ... $ month : int 1 2 3 4 5 6 7 8 9 10 ... $ rate : Time-Series from 2017 to 2018: 2.71 2.95 2.56 2.31 1.95 ...> class(tmp)[1] "data.frame"> str(tmp)'data.frame':12 obs. of 4 variables: $ prd_code: num 1.32e+10 1.32e+10 1.32e+10 1.32e+10 1.32e+10 ... $ year : Factor w/ 1 level "2017": 1 1 1 1 1 1 1 1 1 1 ... $ month : int 1 2 3 4 5 6 7 8 9 10 ... $ rate : Time-Series from 2017 to 2018: 2.71 2.95 2.56 2.31 1.95 ...
这个类型前所未见,查后得知是时间序列类型,附带时间属性。现在我并不需要它的时间,因此用as.numeric()做一个强制转换:
output <- rbind(output,data.frame(prd_code=src_dat$prod_no[(1+24*n)],year="2017",month=seq(1:12),rate=as.numeric(salesForecast2$mean)) )
问题解决。阅读全文
0 0
- R语言学习-问题解决-Error in `[<-.ts`(`*tmp*`,...only replacement of elements is allowed
- R语言学习笔记-Error in ts(x):对象不是矩阵问题解决
- R语言学习-问题解决-Error in output$nodeID : $ operator is invalid for atomic vectors
- Error 1313: RETURN is only allowed in a FUNCTION SQL Statement
- 报错:”Gradle error : Write access is allowed from event dispatch thread only in android studio
- 报错:”Gradle error : Write access is allowed from event dispatch thread only in android studio
- 报错:”Gradle error : Write access is allowed from event dispatch thread only in android studio
- Gradle error : Write access is allowed from event dispatch thread only in android studio
- @synthesize of 'weak' property is only allowed in ARC or GC mode
- iOS开发中的 @synthesize of 'weak' property is only allowed in
- 12、@synthesize of ‘weak’ property is only allowed in ARC or GC mode
- @synthesize of 'weak' property is only allowed in ARC or GC mode
- 彻底解决:@synthesize of 'weak' property is only allowed in ARC or GC mode :问题
- @synthesize of 'weak' property is only allowed in ARC or GC mode
- Error:Content is not allowed in prolog.
- 使用第三方框架的时候报“synthesize of ‘weak’ property is only allowed in ARC or GC mode”错
- 新技能get,在ios下提示“@synthesize of ‘weak’ property is only allowed in ARC or GC mode”
- org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog.
- 把一个数组写到文件中并读出来
- Html5生成验证码
- 2017西安交大ACM小学期数论 [更新学号]
- spring cloud 微服务架构
- 【Opencv】2D射影儿何和变换——柱面投影,图像拼接柱面投影
- R语言学习-问题解决-Error in `[<-.ts`(`*tmp*`,...only replacement of elements is allowed
- 史上最简单的 SpringCloud 教程 | 终章
- css3 字数限制,多出用...代替
- 支持手势缩放的ImageView
- 剑指offer面试题[30]-最小的k个数
- 典型递归问题整理
- lucene 3(相关度排序)
- Android禁止ViewPager的左右滑动
- Java实现-搜索二维矩阵