问题描述
限时送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:关键词]
发布评论