Skip to content
Prev 228628 / 398500 Next

converting a time to nearest half-hour

By entering "trunc.POSIXt" at the R commandline, you can see the standard truncate implementation. Riffing on this, 

roundhalfhour <- function( x ) {
 x <- as.POSIXlt( x + as.difftime( 15, units="mins" ) )
 x$sec <- 0
 x$min <- 30*(x$min %/% 30)
 as.POSIXct(x)
}

The as.double approach ought to work also, but rounding error might be a problem.
"David Winsemius" <dwinsemius at comcast.net> wrote:

            
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.