[英]convert hourly data into timeseries in r
I have data of each hour of approximately 3 years, i am working on how to convert it into time series can u pleas help me out我有大约 3 年的每小时数据,我正在研究如何将其转换为时间序列,请帮帮我
head(hourly)
Date...Hour.Block hour A1 A2 E1 E2 N1 N2
1 01-01-2015 00 - 01 2000.54 2000.54 2000.54 2000.54 2000.54 2000.54
2 01 - 02 1849.80 1849.80 1849.80 1849.80 1849.80 1849.80
3 02 - 03 1699.59 1699.59 1699.59 1699.59 1699.59 1699.59
4 03 - 04 1699.47 1699.47 1699.47 1699.47 1699.47 1699.47
5 04 - 05 1699.57 1699.57 1699.57 1699.57 1699.57 1699.57
6 05 - 06 1764.42 1764.42 1764.42 1764.42 1764.42 1764.42
N3 S1 S2 W1 W2 W3 MCP
1 2000.54 2000.54 2000.54 1999.27 1999.27 1999.27 1899.85
2 1849.8 1849.80 1849.8 1849.80 1849.80 1849.80 1829.33
3 1699.59 1699.59 1699.59 1699.59 1699.59 1699.59 1699.41
4 1699.47 1699.47 1699.47 1699.47 1699.47 1699.47 1699.31
5 1699.57 1699.57 1699.57 1699.57 1699.57 1699.57 1699.37
6 1764.42 3610.61 3610.61 1764.42 1764.42 1764.42 1779.00
I want to convert only one column data like A1
or MCP
我只想转换一列数据,如A1
或MCP
library(lubridate)
dmy_hms("01-01-2015 00:00:00") + hours(1: (24*365*3 + 24*366))
2018 answer 2018 答案
You can convert your hourly data(say, train_df) into time series(train_xts) with this line of code:您可以使用以下代码行将每小时数据(例如 train_df)转换为时间序列(train_xts):
train_xts <- xts(x = train_df, order.by = train_meta_lj$timestamp)
ts does not work well with hourly time series. ts 不适用于每小时时间序列。 It is better to use zoo or xts which is a subclass of zoo.最好使用 zoo 或 xts,它们是 zoo 的子类。 order.by is the column that contains your time observations. order.by 是包含您的时间观察的列。 Note: the timestamp observation should be in ascending order注意:时间戳观察应按升序排列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.