2013-02-20 30 views
0

給定一系列事件,是否有算法用於確定某個事件是否在特定時間段內發生?例如,給定用戶登錄列表,是否有任何三十天的時間段包含超過10次登錄?時間線事件集中

我可以想出幾個蠻力的方法來做到這一點,只是想知道是否有一種算法或名稱爲這種問題,我沒有與通常的谷歌搜索出現。

回答

0

通常它被稱爲binning。基本上使用計數作爲彙總函數將一個變量(,例如events)彙總在索引(,例如time)上。

既然你沒有提供的數據,我會只顯示一個簡單的例子:

# Start with a dataframe of dates and number of events 
data <- data.frame(date=paste('2013', rep(1:12, each=20), rep(1:20, times=12), sep='-'), 
        logins=rpois(12*20, 5)) 

# Make sure to store dates as class Date, it can be useful for other purposes 
data$date <- as.Date(data$date) 

# Now bin it. This is just a dirty trick, exactly how you do it depends on what you want. 
# Lets just sum the number of events for each month 
data$month <- sub('-', '', substr(data$date, 6, 7)) 
aggregate(logins~month, data=data, sum, na.rm=TRUE) 

這是你想要的嗎?