R:绘制动物园中的一阶差分
我试图在同一个图上绘制两个时间序列(动物园对象)的第一个差异,以进行比较。我使用:
plot(na.approx(cbind(diff(n),diff(d))),lty=c(1,2),screen=1)
其中n和d是两个系列。我收到以下错误消息:
Error in plot.zoo(na.approx(diff(merge(n, d))), lty = c(1, 2), screen=1, :
scatter plots only for univariate zoo series
如果我绘制 n 和 d 而不是它们的差异,则相同的命令可以正常工作。
如果我在这里遗漏了什么,请帮忙。
代码块:
library(zoo)
z <- read.zoo("C:\\Users\\lenovo\\Desktop\\qCombined\\pswiss.txt",header=TRUE,sep="", format="%m/ %d/ %Y" )
colnames(z) <- tolower(colnames(z))
ls <- log(z$inr.chf)
lpstar <- log(z$cpiswiss)
lp <- log(z$cpiind)
n <- ls + lpstar
d <- lp
z包含日期、瑞士CPI、印度CPI和汇率:
cpiswiss cpiind inr.chf
2000-01-01 100.0000 100.00000 27.3661
2000-02-01 100.4016 99.76798 26.6971
2000-03-01 100.4016 100.69606 26.2205
I am trying to plot the first differences of two time series (zoo objects) on the same plot for comparison purposes. I use:
plot(na.approx(cbind(diff(n),diff(d))),lty=c(1,2),screen=1)
where n and d are the two series. I get the following error message:
Error in plot.zoo(na.approx(diff(merge(n, d))), lty = c(1, 2), screen=1, :
scatter plots only for univariate zoo series
The same command works properly if i plot n and d instead of their differences.
Please help if i am missing something here.
Code chunk:
library(zoo)
z <- read.zoo("C:\\Users\\lenovo\\Desktop\\qCombined\\pswiss.txt",header=TRUE,sep="", format="%m/ %d/ %Y" )
colnames(z) <- tolower(colnames(z))
ls <- log(z$inr.chf)
lpstar <- log(z$cpiswiss)
lp <- log(z$cpiind)
n <- ls + lpstar
d <- lp
z contains Date,Swiss CPI,Indian CPI and the exchange rate:
cpiswiss cpiind inr.chf
2000-01-01 100.0000 100.00000 27.3661
2000-02-01 100.4016 99.76798 26.6971
2000-03-01 100.4016 100.69606 26.2205
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论