On Fri, Jul 23, 2010 at 12:35 PM, wrote:
> David, Stephen,
> You're right - it's the time zone conventions that threw me as well. I tried
> those round() operations earlier, but inevitably ended up being either an
> hour behind. Even when I specified my time zone, it didn't make any
> differen
@r-project.org
Subject: Re: [R] converting a time to nearest half-hour
On Jul 23, 2010, at 12:04 PM, stephen sefick wrote:
> If you have a zoo series this should work. If it doesn't then please
> tell me because I think it works.
>
> snap2min <- function(zoo, min="00:15:00&qu
The arithmetic that David describes should work fine (POSIXct is
internally in UTC) unless you are in the Chatham Islands (which has a
UTC+12:45 time zone [1]) or Nepal (UTC+05:45 [2]) or some such place
with a funny idea about when the 1/2 hour mark is.
The formatting of the output may be tr
This truncates to quarter-hour rather than rounding to half-hour.
"stephen sefick" wrote:
>If you have a zoo series this should work. If it doesn't then please
>tell me because I think it works.
>
>snap2min <- function(zoo, min="00:15:00"){
>min15 <- times(min)
>a <- aggregate(zoo, trunc(time(z
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 w
On Jul 23, 2010, at 12:04 PM, stephen sefick wrote:
If you have a zoo series this should work. If it doesn't then please
tell me because I think it works.
snap2min <- function(zoo, min="00:15:00"){
min15 <- times(min)
a <- aggregate(zoo, trunc(time(zoo), min15), function(x) mean(x,
na.rm=TR
If you have a zoo series this should work. If it doesn't then please
tell me because I think it works.
snap2min <- function(zoo, min="00:15:00"){
min15 <- times(min)
a <- aggregate(zoo, trunc(time(zoo), min15), function(x) mean(x, na.rm=TRUE))
}
hth
Stephen Sefick
On Fri, Jul 23, 2010 at 11:00
On Jul 23, 2010, at 11:35 AM, David Winsemius wrote:
On Jul 23, 2010, at 11:20 AM, > 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
On Jul 23, 2010, at 11:20 AM, > 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 a
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?
Thanks,
Murali
10 matches
Mail list logo