简体   繁体   English

在R中使用半小时数据创建时间序列

[英]Creating a Time Series with Half Hourly Data in R

This is my first time ever asking a question on Stack Overflow and I'm a programming novice so any advice as to how to improve my question asking abilities would be appreciated. 这是我第一次问有关Stack Overflow的问题,而且我是一名编程新手,因此,对于如何提高我的提问能力的任何建议,我们将不胜感激。

Onto my question: I have two csv files, one containing three columns (date time in dd/mm/yyyy hh:(00 or 30) format, production of a certain product, and demand for said product), and the other containing several columns (decomposition of the date time into year, month, day, hour, and whether it is :00 or :30 represented by 1 or 2 respectively, alongside several columns for independent variables which may affect production/demand of said product). 关于我的问题:我有两个csv文件,一个包含三列(日期时间以dd / mm / yyyy hh:(00或30)格式,某种产品的生产,以及对该产品的需求),另一种包含几列列(将日期时间分解为年,月,日,小时,以及分别用1或2表示的00:或30:日期时间,以及几个独立变量的列,这些变量可能会影响所述产品的生产/需求)。

I've only played around with the first csv file, converting the string into a datetime object but the ts() function won't recognise the datetime objects as my times. 我只玩过第一个csv文件,将字符串转换为datetime对象,但ts()函数无法将datetime对象识别为我的时间。 I've tried adjusting the frequency parameter but ultimately failed and have no idea how to create a time series using half hourly data. 我尝试调整频率参数,但最终失败了,并且不知道如何使用半小时数据创建时间序列。 Would appreciate any help. 将不胜感激。

Thanks in advance! 提前致谢!

My suggestion is to apply the "difftime" over all your time data. 我的建议是对所有时间数据应用“ difftime”。 For instance, like following code, you can use your initial time (the time of first record) for all comparisons as time_start and the others as time_finish. 例如,像下面的代码一样,您可以将所有比较的初始时间(首次记录的时间)用作time_start,将其他比较用作time_finish。 Then it return the time intervals as number of seconds and then you are ready to use other column values as the value of the time stamps. 然后,它返回时间间隔(以秒为单位),然后准备使用其他列值作为时间戳记的值。

interval=as.integer(difftime(strptime(time_finish,"%H:%M"),strptime(time_start,"%H:%M"),units = "sec")) interval = as.integer(difftime(strptime(time_finish,“%H:%M”),strptime(time_start,“%H:%M”),units =“ sec”))

Second 0 10 15 .... 秒0 10 15 ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM