【问题标题】:need finite 'xlim' values on Zoo object plottingZoo对象绘图需要有限的“xlim”值
【发布时间】:2015-01-20 14:57:31
【问题描述】:

我有以下动物园对象:

x<-read.zoo("values.txt",format="%H:%M:%OS",sep=",",header=F,FUN=as.POSIXct)

x 如下所示:

2015-01-20 17:39:56 367 0
2015-01-20 17:39:56 236 0
2015-01-20 17:39:58 542 0
2015-01-20 17:39:58 260 0

现在我在第二个时间间隔内聚合以获取每秒而不是毫秒级别的值: > x_uniq<-aggregate(x,format(time(x),"%H:%M:%S"),mean)

x_uniq 如下:

17:39:55 403.0000 0.0
17:39:56 301.5000 0.0
17:39:58 401.0000 0.0
17:40:00 607.0000 0.0

当我尝试绘制它时,我收到以下错误:

plot(x_uniq,plot.type = "single", col = c("red", "blue"),lwd = 2)
plot.window(...) 中的错误:需要有限的“xlim”值
另外:警告消息:
1:在 xy.coords(x, y, xlabel, ylabel, log) 中:强制引入的 NA
2:在 min(x) 中:min 没有非缺失参数;返回 Inf
3:在 max(x) 中:max 没有非缺失参数;返回 -Inf

按照我的理解,现在是这样,因为现在已经将时间转换为字符。但我不确定如何将其转换回来。有人可以帮忙吗? 谢谢!

【问题讨论】:

    标签: python r plot zoo


    【解决方案1】:

    这个问题省略了输入,只显示了read.zoo 语句的输出,所以我们真的不知道你有什么,但假设它看起来像下面这样试试这个:

    Lines <- 
    "2015-01-20 17:39:56,367,0
    2015-01-20 17:39:56,236,0
    2015-01-20 17:39:58,542,0
    2015-01-20 17:39:58,260,0"
    
    library(zoo)
    z <- read.zoo(text = Lines, sep = ",", tz = "", aggregate = mean)
    plot(z)
    

    【讨论】:

      猜你喜欢
      • 2018-01-26
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多