按日期和时间选择时间序列对象的间隔 [英] Select interval of time series object by date and time

查看:194
本文介绍了按日期和时间选择时间序列对象的间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于如何管理空气质量数据库中的日期和时间的信息,该数据库每天从2002年到2008年每天每十分钟保存一次数据。

My question is about how to manage the dates and times in an air quality database, which saved data every ten minutes all day, every day from 2002 through 2008.

我想生成多个分析图,但仅参考上午6:00至上午8:00,我试图在所需的时间间隔内生成图表,但R工具始终绘制24小时内的图表。

I want to generate several analysis and plots, but referring only to the morning peak hours which go from 6:00 through 8:00 a.m. I have tried to generate the diagrams in the needed interval but the R tool always plots the 24 hours in a day distorting, therefore, the available data for the peak hours.

我非常感谢您提供有关如何仅选择和绘制高峰时段的时间间隔以及如何绘制高峰时段的指导。生成几个图表。

I would hugely appreciate your guidance on how to select and plot interval in the peak hour only and how to generate the several diagrams.

我有下一个脚本来生成日期间隔,但是我想汇总小时间隔(6-8 am)并仅绘制间隔数据:

I have the next script to generate a date interval, but I want to agregate hour interval (6-8 am) and plot only the interval data:

# select interval
start.date = as.POSIXct("2007-03-27 05:00", tz = "GMT")
end.date = as.POSIXct("2007-05-27 05:00", tz = "GMT")
subdata = subset(mydata, date >= start.date & date <= end.date,
select = c(date, nox, co))
#
#plot the variables


推荐答案

我建议您使用时间序列类而不是data.frame。使用xts每天按时间间隔进行子集很容易:

I recommend you use a time series class instead of a data.frame. Subsetting by a time interval each day is easy with xts:

# use DWin's example data
Data <- data.frame(a=rnorm(240),
  dtm=as.POSIXct("2007-03-27 05:00", tz="GMT")+3600*(1:240))
# create xts object
library(xts)
x <- xts(Data[,"a"], Data[,"dtm"])
# subset by time of day
y <- x["T06:00/T08:00"]
# plot
plot(y)  # plots all 24 hours of each day
# use chartSeries from quantmod to avoid above behavior
library(quantmod)
chartSeries(y)

这篇关于按日期和时间选择时间序列对象的间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆