Skip to content

Instantly share code, notes, and snippets.

@ijlyttle
Created April 23, 2013 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijlyttle/5444643 to your computer and use it in GitHub Desktop.
Save ijlyttle/5444643 to your computer and use it in GitHub Desktop.
using ddply seems to wipe out the "Duration"
library(plyr)
library(lubridate)
n_intvl <- 48
dur_intvl <- dseconds(900)
intvl_15min <- data.frame(
start = ymd("2001-01-01", tz="America/Chicago") + seq(0, n_intvl-1)*dur_intvl,
dur = rep(dur_intvl, n_intvl)
)
str(intvl_15min)
# note that dur has class Duration
intvl_hour <- ddply(
.data = mutate(intvl_15min, start=floor_date(start, "hour")),
.variables = .(start),
.fun = summarize,
dur = sum(dur)
)
str(intvl_hour)
# note that dur has class numeric
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment