[R] Change data frame to time series data

roslinazairimah zakaria ro@||n@ump @end|ng |rom gm@||@com
Wed Oct 2 03:57:21 CEST 2024


Dear all, I have a data in data frame and would like to change to time
series data. Thank you for any help given.






> str(dt)'data.frame':	525600 obs. of  3 variables:
 $ time             : chr  "2014-01-01 00:00:00" "2014-01-01 00:01:00"
"2014-01-01 00:02:00" "2014-01-01 00:03:00" ...
 $ cnt_charge_events: int  0 0 0 0 0 0 0 0 0 0 ...
 $ count            : int  0 0 0 0 0 0 0 0 0 0 ...

> head(dt)                 time cnt_charge_events count
1 2014-01-01 00:00:00                 0     0
2 2014-01-01 00:01:00                 0     0
3 2014-01-01 00:02:00                 0     0
4 2014-01-01 00:03:00                 0     0
5 2014-01-01 00:04:00                 0     0
6 2014-01-01 00:05:00                 0     0


> dt_ts <- xts(dt$count, dt$time)Error in xts(dt$count, dt$time) :
  order.by requires an appropriate time-based object> head(dt_ts)Time Series:
Start = 1
End = 6
Frequency = 1
  dt_ts.date dt_ts.time dt[, 3]
1      16071          1       0
2      16071          2       0
3      16071          3       0
4      16071          4       0
5      16071          5       0
6      16071          6       0Dear


-- 
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: roslinazairimah using ump.edu.my <roslinazairimah using ump.edu.my>;
roslinaump using gmail.com <roslinaump using gmail.com>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

	[[alternative HTML version deleted]]



More information about the R-help mailing list