我有一个如下所示的数据集:
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轴)的条形图,这意味着在一小时内观察了多少次。 你能帮忙吗? 谢谢, 盖
答案 0 :(得分:2)
这样的事情应该有效:
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)