R时间序列plot.ts() [英] R Time Series plot.ts()
本文介绍了R时间序列plot.ts()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图阅读时间序列并进行plot.ts(),但是结果却很奇怪.也许我做错了.我尝试包括开始日期和结束日期,但输出仍然错误. 任何帮助表示赞赏.谢谢.
I am trying to read in a time series and do a plot.ts(), however I am getting weird results. Perhaps I did something wrong. I tried including the start and end dates but the output is still wrong. Any help appreciated. Thank you.
这是代码和输出:
sales1 <- read.csv("TimeS.csv",header=TRUE)
sales1
salesT <- ts(sales1)
salesT
plot.ts(salesT)
output:
> sales1 <- read.csv("TimeS.csv",header=TRUE)
> sales1
year q1 q2 q3 q4
1 1991 4.8 4.1 6.0 6.5
2 1992 5.8 5.2 6.8 7.4
3 1993 6.0 5.6 7.5 7.8
4 1994 6.3 5.9 8.0 8.4
> salesT <- ts(sales1)
> salesT
Time Series:
Start = 1
End = 4
Frequency = 1
year q1 q2 q3 q4
1 1991 4.8 4.1 6.0 6.5
2 1992 5.8 5.2 6.8 7.4
3 1993 6.0 5.6 7.5 7.8
4 1994 6.3 5.9 8.0 8.4
> plot.ts(salesT)
It looks like I can't paste the plot. instead of 1 graph it has 5 separate
plots stacked onto each other.
推荐答案
原始数据的格式很难直接用于时间序列.您可以尝试以下方法:
The format of the original data is difficult to use directly for a time series. You could try this instead:
sales1 <- t(sales1[,-1])
sales1 <- as.vector(sales1)
my_ts <- ts(sales1, frequency = 4, start=c(1991,1))
plot.ts(my_ts)
这篇关于R时间序列plot.ts()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文