[R] converting a time to nearest half-hour

David Winsemius dwinsemius at comcast.net
Fri Jul 23 17:35:37 CEST 2010


On Jul 23, 2010, at 11:20 AM, <Murali.Menon at avivainvestors.com> <Murali.Menon at avivainvestors.com 
 > wrote:

> Hi folks,
>
> I've got a POSIXct datum as follows:
>
>> Sys.time()
> [1] "2010-07-23 11:29:59 BST"
>
> I want to convert this to the nearest half-hour, i.e., to  
> "2010-07-23 11:30:00 BST"
>
> (If the time were "11:59:ss", I want to convert to "12:00:00").
>
> How to achieve this?

Couldn't you just coerce to numeric, divide by 60(sec)*30(half-hour  
minutes), round to integer, multiply by 60*30,  coerce to POSIXct?

_
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list