datetime - Binning Dates in R -


i struggle dates , times in r, hoping basic task.

here dataset:

> str(temp.df) 'data.frame':   74602 obs. of  2 variables:  $ time : posixct, format: "2011-04-09 03:53:20" "2011-04-09 03:53:15" "2011-04-09 03:53:07" "2011-04-09 03:52:39" ...  $ value: num  1 1 1 1 1 1 1 1 1 1 ...  > head(temp.df$time, n=10)  [1] "2011-04-09 03:53:20 edt" "2011-04-09 03:53:15 edt" "2011-04-09 03:53:07 edt" "2011-04-09 03:52:39 edt"  [5] "2011-04-09 03:52:29 edt" "2011-04-09 03:51:56 edt" "2011-04-09 03:51:54 edt" "2011-04-09 03:51:46 edt"  [9] "2011-04-09 03:51:44 edt" "2011-04-09 03:51:26 edt" 

and convenience...

> dput(head(temp.df$time, n=10)) structure(c(1302335600, 1302335595, 1302335587, 1302335559, 1302335549,  1302335516, 1302335514, 1302335506, 1302335504, 1302335486), class = c("posixct",  "posixt"), tzone = "") 

what looking do:

  • how can find how many hours between min , max date/time?
  • what's best way create summaries of data using 1-hour time buckets?

any can provide appreciated

use proper time series packages zoo and/or xts. example straight pages of aggregate.zoo() aggregates posixct seconds data every 10 minutes

 tt <- seq(10, 2000, 10)  x <- zoo(tt, structure(tt, class = c("posixt", "posixct")))  aggregate(x, time(x) - as.numeric(time(x)) %% 600, mean) 

the to.period() function in xts sure winner. there countless examples here on , on r-sig-finance list.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -