Skip to content
Prev 5223 / 15274 Next

Discretising intra-day data -- how to get by with less memory?

Brian G. Peterson wrote:
Or, an earlier, slower version:

this works well enough to generate a new index on the output of to.period:

# stamp is POSIXct object, like index(x) of an xts object
# n is number of seconds to round to, so n=k in to.period
even_seconds = function(stamp,n=60)
{
  tzone = attr(stamp,"tzone")
  if (is.null(tzone)) { tzone = "" }
  base = as.POSIXct(strptime( format(stamp,"%Y%m%d"), "%Y%m%d" ),tz=tzone)
  i = as.numeric(stamp) - as.numeric(base)
  i = base + n*ceiling(i/n)
  i
}