Skip to content
Prev 299841 / 398503 Next

Questions about doing analysis based on time

Hello,

If I understanding it, what you want are the values below.


half.hours <- function(x){
	s <- strsplit(as.character(x), ":")
	H <- as.integer(sapply(s, `[`, 1))
	M <- as.integer(sapply(s, `[`, 2))
	h <- (H*60 + M)/60
	floor(h/0.5)*0.5
}
half.hours(dat$SunTime)


And this can be used in aggregate.

half.hr <- half.hours(dat$SunTime)
aggregate(SunScore ~ half.hr, data = dat, mean)


Rui Barradas

Em 11-07-2012 14:33, APOCooter escreveu: