Skip to content
Prev 235799 / 398500 Next

Splitting a time + duration into a series of periods

Travers -
    R's date/time abilities are pretty powerful -- you shouldn't have to
resort to outside programs.  Here's how I'd approach the problem:
+ alice, 2010/01/01 10:00, 145
+ bob, 2010/01/01 11:00, 30
+ '),stringsAsFactors=FALSE)
+           as.POSIXct('2010/01/01 12:30'),by=30*60)
+             function(tm)sum(dat$login_time <= tm & dat$login_end > tm)))
                  time count
1 2010-01-01 10:00:00     1
2 2010-01-01 10:30:00     1
3 2010-01-01 11:00:00     2
4 2010-01-01 11:30:00     1
5 2010-01-01 12:00:00     1
6 2010-01-01 12:30:00     0

Hope this helps.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu
On Fri, 24 Sep 2010, Travers Naran wrote: