[R] Insert rows - how can I accomplish this in R

2006-08-18 Thread Sachin J
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 =

Re: [R] Insert rows - how can I accomplish this in R

2006-08-18 Thread Gabor Grothendieck
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

Re: [R] Insert rows - how can I accomplish this in R

2006-08-18 Thread Sachin J
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,

Re: [R] Insert rows - how can I accomplish this in R

2006-08-18 Thread Gabor Grothendieck
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