为什么我在尝试在 R 中绘制 xts 对象时收到错误消息?

发布于 2025-01-18 16:02:56 字数 1388 浏览 2 评论 0原文

我正在尝试在R中绘制XTS对象。以下是我正在运行的代码,它为我提供了错误消息。

outcomes_xts <- xts(true_outcomes, as.yearqtr(end_dates))

plot(as.zoo("outcomes_xts"),
     col = "purple",
     lwd = 4,
     ylab = "Quarterly Change in per-capita GDP (£)",
     main = paste0("ADL(1,1): Pseudo-Out-Of-Sample Forecasts of Differenced",
     " per-capita GDP, United Kingdom"),
     ylim = -200:200)

但是,此代码给了我以下错误消息:

Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y) : NAs introduced by coercion

从我收集的内容中,这可能是由XTS对象中的数据作为字符字符串而不是数字引起的,但是此数据并非如此。它也不是由XTS对象中的N/A引起的 - 我尝试在XTS对象上使用Na.omit(),但我仍然遇到相同的错误。感谢您,谢谢。

这是我运行dput(utemes_xts [1:30])时的结果

structure(c(62, 48, 24, 30, 4, 12, 31, 58, 54, 70, 28, 13, 3, 
33, 46, 20, 37, 15, 31, -52, -131, -169, -149, -37, -10, 8, 37, 
69, 37, -6), class = c("xts", "zoo"), index = structure(c(1057017600, 
1064966400, 1072915200, 1080777600, 1088640000, 1096588800, 1104537600, 
1112313600, 1120176000, 1128124800, 1136073600, 1143849600, 1151712000, 
1159660800, 1167609600, 1175385600, 1183248000, 1191196800, 1199145600, 
1207008000, 1214870400, 1222819200, 1230768000, 1238544000, 1246406400, 
1254355200, 1262304000, 1270080000, 1277942400, 1285891200), tzone = "UTC", tclass = "yearqtr"), .Dim = c(30L, 
1L))

I am trying to plot an xts object in R. Below is the code I am running that gives me the error message.

outcomes_xts <- xts(true_outcomes, as.yearqtr(end_dates))

plot(as.zoo("outcomes_xts"),
     col = "purple",
     lwd = 4,
     ylab = "Quarterly Change in per-capita GDP (£)",
     main = paste0("ADL(1,1): Pseudo-Out-Of-Sample Forecasts of Differenced",
     " per-capita GDP, United Kingdom"),
     ylim = -200:200)

However this code gives me the following error message:

Warning messages:
1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
2: In xy.coords(x, y) : NAs introduced by coercion

From what I gather, this can be caused by the data in the xts object being stored as character strings rather than numeric, but this isn't the case with this data. Neither is it caused by n/a's in the xts object - I have tried using na.omit() on the xts object but I still get the same error. Help would be appreciated, thank you.

Here is my result when I run dput(outcomes_xts[1:30])

structure(c(62, 48, 24, 30, 4, 12, 31, 58, 54, 70, 28, 13, 3, 
33, 46, 20, 37, 15, 31, -52, -131, -169, -149, -37, -10, 8, 37, 
69, 37, -6), class = c("xts", "zoo"), index = structure(c(1057017600, 
1064966400, 1072915200, 1080777600, 1088640000, 1096588800, 1104537600, 
1112313600, 1120176000, 1128124800, 1136073600, 1143849600, 1151712000, 
1159660800, 1167609600, 1175385600, 1183248000, 1191196800, 1199145600, 
1207008000, 1214870400, 1222819200, 1230768000, 1238544000, 1246406400, 
1254355200, 1262304000, 1270080000, 1277942400, 1285891200), tzone = "UTC", tclass = "yearqtr"), .Dim = c(30L, 
1L))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文