2015-02-05 17 views
3

我在R中有一个df,格式如下。有什么能聚集这每小时的时间间隔的基础上的最简单的方法,目前是每分钟R中小时间隔的总时间列

    theTime24 Amount 
988 2015-02-04 23:53:00  2 
989 2015-02-04 23:55:00  1 
990 2015-02-04 23:56:00  3 
991 2015-02-04 23:57:00  2 
992 2015-02-04 23:58:00  1 
993 2015-02-04 23:59:00  2 
+1

您可以通过时间段使用'format'到组,沿线(数据格式(as.POSIXct(dat $ theTime24),“%Y-%m-%d%H”),data = dat,sum)[[假设函数是sum]] – user20650

+1

@ user20650 - 谢谢你钉了它!按我期望的那样工作:) – K3rn3l5

回答

3

(因为谁回答用户(@ user20650)增加一条,作为一个评论,我回答我的问题)

aggregate(Amount ~ format(as.POSIXct(countByCountryTime$theTime24), "%Y-%m-%d %H"), data=countByCountryTime, sum) 
0

我会格式化日期为POSIX,转换成每小时,和聚集。

dt$theTIME24<-as.POSIXct(strptime(dt$theTIME24,format="%Y-%m-%d %H:%M:%S")) 
dt$theTIME24.h<-as.POSIXct(strptime(dt$theTIME24,format="%Y-%m-%d %H")) 
amt<-aggregate(dt$Amount,by=list(dt$theTIME24.h),mean)