[英]How are the intermediate values between observations in time series calculated in ts() in R?
[英]How to bin observations over a time series in r?
我有一個數據集,看起來像這樣:
VisitID Start
1 0 2015-02-15 09:46:43.17
2 1 2015-02-15 09:47:37.84
3 2 2015-02-15 09:58:46.42
4 3 2015-02-15 09:58:48.46
5 4 2015-02-15 10:28:25.09
6 5 2015-02-15 10:33:43.53
我想繪制每小時(y軸)相對於絕對時間(x軸)的計數的條形圖,這表示一小時內有多少觀察。 你能幫忙嗎? 謝了,兄弟們
這樣的事情應該工作:
DF <- read.csv(text=
"VisitID,Start
0,2015-02-15 09:46:43.17
1,2015-02-15 09:47:37.84
2,2015-02-15 09:58:46.42
3,2015-02-15 09:58:48.46
4,2015-02-15 10:28:25.09
5,2015-02-15 10:33:43.53",stringsAsFactors=FALSE)
DF$StartDate <- strptime(DF$Start, tz='GMT', format="%Y-%m-%d %H:%M:%OS")
hours <- vapply(split(1:nrow(DF),format(DF$StartDate,"%Y-%m-%d %H:00:00",tz='UTC')),length,0)
barplot(hours)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.