Jessica

Any good?

lines <-"DateTime, Q
2004-12-09 15:30:01, 2
2004-12-09 15:30:01, 1
2004-12-09 15:30:06, 1
2004-12-09 15:30:14, 5
2004-12-09 15:30:21, 1
2004-12-09 15:30:22, 11
2004-12-09 15:30:24, 4
2004-12-09 15:30:32, 1
2004-12-09 15:30:32, 1
2004-12-09 15:30:32, 3
2004-12-09 15:30:41, 4"

d = read.table(textConnection(lines), sep="," ,header = TRUE)

d$DateTime = as.POSIXct(d$DateTime) 

time <- seq(as.POSIXct('2004-12-09 15:30:00'),by='5 sec', length=10)

bins = cut(d$DateTime,breaks=time)

counts = as.data.frame(tapply(d$Q,bins,sum))

# Clean up 
counts[is.na(counts)]=0
colnames(counts) = "Counts"

print(counts)

HTH

Pete
-- 
View this message in context: 
http://r.789695.n4.nabble.com/time-bin-sum-tp3252376p3253400.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to