# NOT RUN {
x <- 1:6
i <- as.Date("2019-01-01") + c(-2:2, 31)
block(i, i, period = "year")
# Data frames are split row wise
df <- data.frame(x = x, i = i)
block(df, i, period = "month")
# Iterate over these blocks to apply a function over
# non-overlapping period blocks. For example, to compute a
# mean over yearly or monthly blocks.
vapply(block(x, i, "year"), mean, numeric(1))
vapply(block(x, i, "month"), mean, numeric(1))
# block by every 2 months, ensuring that we start counting
# the 1st of the 2 months from `2019-01-01`
block(i, i, period = "month", every = 2, origin = as.Date("2019-01-01"))
# Use the `origin` to instead start counting from `2018-12-01`, meaning
# that [2018-12, 2019-01] gets bucketed together.
block(i, i, period = "month", every = 2, origin = as.Date("2018-12-01"))
# }
Run the code above in your browser using DataLab