Hi,
I have following dataframe. Column A indicates months.
DF - structure(list(A = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1,
2, 3, 4, 5, 7, 8, 11, 12, 1, 2, 3, 4, 5, 8), B = c(0, 0, 0, 8,
0, 19, 5, 19, 0, 0, 0, 11, 0, 8, 5, 11, 19, 8, 11, 10, 0, 8,
36, 10, 16, 10, 22)), .Names =
Here are two solutions. In both we break up DF into rows
which start with 1.
In solution #1 we create a new data frame with the required sequence
for A and zeros for B and then we fill it in.
In solution #2 we convert each set of rows to a zoo object z
where column A is the times and B is the
Gabor,
Thanks a lot for the help. The 1st method works fine. In 2nd method I am
getting following error.
do.call(rbind, by(DF, cumsum(DF$A == 1), f))
Error in zoo(, time(as.ts(z)), z, fill = 0) :
unused argument(s) (fill ...)
Unable to figure out the cause.
Thanks,
I did run it so I am not sure how the error crept in. Anyways,
I have fixed it and a corrected version is below.
---
Here are two solutions. In both we break up DF into rows
which start with 1.
In #1 we create a new data frame with the required sequence
for A and zeros for B and then we fill