Skip to content
Prev 345898 / 398502 Next

Help with Time

Perhaps this ...

roundToHalf <- function(t) { 
	t <- as.POSIXlt(t)
	if (t$min < 15) {
		t$min <- 0
	} 
	else if (t$min < 45) {
		t$min <- 30		
	}
	else {
		t$min <- 0
		t$hour <- t$hour + 1
	}
	return(t)
}

# check
for (i in 1:20) {
	a <- Sys.time() + (i*490)  # semi arbitrary intervals
	b <- roundToHalf(a)
	print(paste(a, "  ", b))
}


B.
On Nov 21, 2014, at 5:55 PM, Raghuraman Ramachandran <optionsraghu at gmail.com> wrote: