Hello Everyone,

I have data at weekly intervals.
The data structure is something like this.

df1 <-
date            a
1/7/2020     3
1/14/2020   6
1/21/2021   7

I would like to convert the data from the weekly
interval to the daily interval. Something like this.

date            a
1/7/2020    0.5
1/8/2020    0.3
1/9/2020    0.7


I am using the following codes

d1 <- nrow(df1)

df2 <- data.frame(matrix(NA, nrow = (d1)*7, ncol = 1)

inc <- 0
for (i in 1:nrow(df1)) {
  for (j in 1:7) {
    inc <- inc + 1
    df2[inc,1] <- df1[i,1]/7
  }
}
rm(df1)



However, the sum of the daily values generated in df2 differ
from the original value in the df1 data frame. There is a 1-2% discrepancy.
I would appreciate it if someone could suggest how to improve the codes.

Thanks,
Bhaskar

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to