使用 xts/zoo R 绘制一天中一小时的值

编程入门 行业动态 更新时间:2024-10-25 06:23:15
本文介绍了使用 xts/zoo R 绘制一天中一小时的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我确实有一个像这样的时间序列(分钟值):

I do have a time-series looking like this (minute values):

   "timestamp", value 
    "2012-04-09 05:03:00",2
    "2012-04-09 05:04:00",4
    "2012-04-09 05:05:00",5
    "2012-04-09 05:06:00",0
    "2012-04-09 05:07:00",0
    "2012-04-09 05:08:00",3
    "2012-04-09 05:09:00",0
    "2012-04-09 05:10:00",1

是否有一种简单的方法可以在一天中的一小时内绘制这些值:从 1 到 24 小时(或 0 和 23)的 X 轴.所以 - 第 5 小时 5:00 和 5:59 之间的所有值等等.它不取决于日期,我只对当天的小时数感兴趣.谢谢!

Is there an easy way to plot these values over the hour of the day: X-Axis from 1 to 24 hours (or 0 and 23). So - all values between 5:00 and 5:59 over the 5th hour etc. It doesn't depend wich date, I am just interested in the houers of the day. Thank you!

附加问题:我可以将其绘制为箱线图吗?现在是动物园格式的 plot(df$hh,df$coredata.._data..).

Additional Question: Can I plot this as a boxplot? Right now it's plot(df$hh,df$coredata.._data..)in zoo format.

推荐答案

使用 xts 包,你可以使用 .indexhour 泛型函数来格式化一个 xts 对象的索引数小时.

Using xts package, you can use .indexhour Generic functions to format the index of an xts object to hours.

比如我读取数据,

dat <- read.zoo(text='timestamp, value 
    "2012-04-09 05:03:00",2
    "2012-04-09 05:04:00",4
    "2012-04-09 05:05:00",5
    "2012-04-09 05:06:00",0
    "2012-04-09 05:07:00",0
    "2012-04-09 05:08:00",3
    "2012-04-09 05:09:00",0
    "2012-04-09 05:10:00",1',header=TRUE,tz='',index=0:1,sep=',')

transform(dat, hh = .indexhour(dat))
                    coredata.._data.. hh
2012-04-09 05:03:00                 2  5
2012-04-09 05:04:00                 4  5
2012-04-09 05:05:00                 5  5
2012-04-09 05:06:00                 0  5
2012-04-09 05:07:00                 0  5
2012-04-09 05:08:00                 3  5
2012-04-09 05:09:00                 0  5
2012-04-09 05:10:00                 1  5

这篇关于使用 xts/zoo R 绘制一天中一小时的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 10:46:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1392844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:xts   zoo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!