search for: uniquetim

Displaying 1 result from an estimated 1 matches for "uniquetim".

Did you mean: uniqueid
2007 Jul 31
1
A complicated 'aggregate'
...me 11:00:01 34.6 2500 11:00:02 34.5 1000 I currently do this using a loop, and the result is abysmally slow: f <- function(x) { retval <- c(0, 0); x <- coredata(x); retval[2] <- sum(x[,2]); retval[1] <- sum(x[,1] * x[,2]) / retval[2]; retval; } #ts is a zoo timeseries uniqueTimes <- unique(index(ts)) tmpMat <- NULL for(i in 1:length(uniqueTimes)) { tmpMat <- rbind(tmpMat, f(ts[uniqueTimes[i]])); } ts.agg <- zooreg(tmpMat, order.by=uniqueTimes); I'm sure the above can be done with aggregate or tapply or by or something, but I haven't managed to g...