lubridate package for date and time management in R

References

Load packages

library(lubridate)

Demo

## Load data
data(lakers)
summary(lakers)
##       date            opponent          game_type             time               period        etype          
##  Min.   :20081028   Length:34624       Length:34624       Length:34624       Min.   :1.00   Length:34624      
##  1st Qu.:20081210   Class :character   Class :character   Class :character   1st Qu.:2.00   Class :character  
##  Median :20090121   Mode  :character   Mode  :character   Mode  :character   Median :3.00   Mode  :character  
##  Mean   :20086944                                                            Mean   :2.54                     
##  3rd Qu.:20090309                                                            3rd Qu.:4.00                     
##  Max.   :20090414                                                            Max.   :5.00                     
##                                                                                                               
##      team              player             result              points          type                 x        
##  Length:34624       Length:34624       Length:34624       Min.   :0.000   Length:34624       Min.   : 0     
##  Class :character   Class :character   Class :character   1st Qu.:0.000   Class :character   1st Qu.:20     
##  Mode  :character   Mode  :character   Mode  :character   Median :0.000   Mode  :character   Median :25     
##                                                           Mean   :0.463                      Mean   :25     
##                                                           3rd Qu.:1.000                      3rd Qu.:31     
##                                                           Max.   :3.000                      Max.   :51     
##                                                                                              NA's   :21557  
##        y        
##  Min.   : 3     
##  1st Qu.: 6     
##  Median :10     
##  Mean   :13     
##  3rd Qu.:20     
##  Max.   :90     
##  NA's   :21557

## Check time in character
head(lakers$time)
## [1] "12:00" "11:39" "11:37" "11:25" "11:23" "11:22"

## Convert time
lakers$time <- hm(lakers$time)

## Now in lubridate class
class(lakers$time)
## [1] "Period"
## attr(,"package")
## [1] "lubridate"

## Then numerical comparison can be made
table(lakers$time > hm("01:00"))
## 
## FALSE  TRUE 
##  3894 30730