首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示错误前导零的时间序列图

显示错误前导零的时间序列图
EN

Stack Overflow用户
提问于 2019-02-12 03:21:37
回答 1查看 163关注 0票数 1

我在每月的数据上运行时间序列,没有缺失值。无论我将"start=c“设置为哪一年,我都会得到几个月/年的零值。

从2016年开始:

代码语言:javascript
复制
    date <- as.Date(as.yearmon(format(Vended$Year_Month),"%m_%Y"))
    timeseries <- ts(Vended$OTIF, start = c(2016), end=c(2018), 
    frequency=12)
    plot.ts(timeseries)

无开始日期:

代码语言:javascript
复制
    date <- as.Date(as.yearmon(format(VendedTS$YearMonth),"%m_%Y"))
    timeseries2 <- ts(VendedTS$OTIF,end=c(2018), frequency=12)
    plot.ts(timeseries2) 

2016作为开始日期:

无开始日期:

下面是我的数据的第25-35行的dput (我希望是这样)。

代码语言:javascript
复制
> small<- (VendedTS[25:35,])
> dput(small)
structure(list(YearMonth = c("OCT 2007", "NOV 2007", "DEC 2007", 
"JAN 2008", "FEB 2008", "MAR 2008", "APR 2008", "MAY 2008", "JUN 2008", 
"JUL 2008", "AUG 2008"), TR_CountofLines = c(40004, 33026, 38336, 
21142, 22547, 27088, 40489, 47710, 41008, 36740, 29112), TR_Value_LineItems = c(3454320.63, 
3617021.03, 4055182.81, 2471699.18, 2128728.17, 2250244.34, 3081359.17, 
3906115.74, 2932821.35, 2679508.65, 2195936.78), OTIF = c(0.28037196280372, 
0.14748985647672, 0.04249269616027, 0.15717529089017, 0.24876923759258, 
0.49556999409333, 0.51194151497938, 0.12167260532383, 0.30598907530238, 
0.22852476864453, 0.52442291838417)), row.names = c(NA, -11L), class = c("tbl_df", 
"tbl", "data.frame")

编辑:我确实希望看到2005-2007年的0值,但在那之后就没有了。

提前感谢!安妮

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-12 06:23:12

使用您的“小”数据子集,尝试以下操作:

代码语言:javascript
复制
library(dplyr)
library(tidyr)
library(lubridate)
library(R.utils)

tidyr::separate(small, col = "YearMonth", into = c("Month", "Year")) %>%
  mutate(Month = R.utils::capitalize(tolower(Month))) %>%
  mutate(Day = "1") %>%
  select(Year, Month, Day, everything()) %>%
  unite(col = "Date", Year, Month, Day, sep = "-") %>%
  mutate(Date = lubridate::ymd(Date)) -> small2

timeseries <- ts(small2$OTIF, start = c(2007, 10), end = c(2008, 8), frequency = 12)
plot(timeseries)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54637646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档