R语言学习-问题解决-Error in `[<-.ts`(`*tmp*`,...only replacement of elements is allowed
2017-07-05 10:55
441 查看
在输出时间序列结果的时候,出现以下问题:
这个类型前所未见,查后得知是时间序列类型,附带时间属性。现在我并不需要它的时间,因此用as.numeric()做一个强制转换:
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 rate 1 13213798874 2017 1 2.711025 2 13213798874 2017 2 2.954181 3 13213798874 2017 3 2.561491 4 13213798874 2017 4 2.313876 5 13213798874 2017 5 1.948865 6 13213798874 2017 6 1.329617 7 13213798874 2017 7 2.550668 8 13213798874 2017 8 2.089158 9 13213798874 2017 9 1.909078 10 13213798874 2017 10 2.006295 11 13213798874 2017 11 1.941801 12 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 rate 1 13213818469 2017 1 2.711025 2 13213818469 2017 2 2.954181 3 13213818469 2017 3 2.561491 4 13213818469 2017 4 2.313876 5 13213818469 2017 5 1.948865 6 13213818469 2017 6 1.329617 7 13213818469 2017 7 2.550668 8 13213818469 2017 8 2.089158 9 13213818469 2017 9 1.909078 10 13213818469 2017 10 2.006295 11 13213818469 2017 11 1.941801 12 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)) )问题解决。
相关文章推荐
- 彻底解决:@synthesize of 'weak' property is only allowed in ARC or GC mode :问题
- R语言学习笔记-Error in ts(x):对象不是矩阵问题解决
- 嵌套错误Inline markup blocks (@<p>Content</p>) cannot be nested. Only one level of inline markup is allowed
- vue学习:解决Apycharm的 * is only available in ES6(use 'esversion: 6') 问题
- R语言学习笔记-Error in ts(x):对象不是矩阵问题解决
- vue学习:解决Atom中的 * is only available in ES6(use 'esversion: 6') 问题
- R语言学习-问题解决-Error in output$nodeID : $ operator is invalid for atomic vectors
- org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog.
- Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 775920 bytes) 问题解决
- @synthesize of 'weak' property is only allowed in ARC or GC mode
- R语言-Error in file(out, "wt") : 无法打开链结问题解决
- Android-Android studio 出现 Error: NDK integration is deprecated in the current plugin. 问题解决
- @synthesize of 'weak' property is only allowed in ARC or GC mode
- Error 1313: RETURN is only allowed in a FUNCTION SQL Statement
- 编译器问题,error: 'for' loop initial declarations are only allowed in C99 mode
- Error 1313: RETURN is only allowed in a FUNCTION SQL Statement
- Ubuntu12.04系统下,解决"Django Error: That port is already in use."报错问题
- mysql error BIGINT UNSIGNED value is out of range in 解决办法
- 解决方法:OTB 中 GDALJP2Box::GDALJP2Box(struct iobuf *),there is the error of unresolved external in debug
- 问题解决 The hierarchy of the type is inconsistent