[R] Converting data from weekly interval to daily interval

Bhaskar Mitra bh@@k@r@ko|k@t@ @end|ng |rom gm@||@com
Tue Jun 8 20:10:13 CEST 2021

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

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.


	[[alternative HTML version deleted]]

More information about the R-help mailing list