Skip to content

Split rows depending on time frame

1 message · Gabor Grothendieck

#
On Mon, Oct 11, 2010 at 5:25 AM, Bert Jacobs
<bert.jacobs at figurestofacts.be> wrote:
Try this:

DF <- data.frame(COL1 = c("A", "B"), COL2 = 40462, COL3 = c(40482, 40478))

do.call("rbind", by(DF, DF$COL1, function(x) with(x, {
	COL2 <- seq(COL2, COL3, 7)
	COL3 <- pmin(COL2 + 6, COL3)
	COL4 <- (COL3 - COL2 + 1) / 7
	data.frame(COL1, COL2, COL3, COL4)
})))