[R] Converting data from weekly interval to daily interval

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Wed Jun 9 00:39:44 CEST 2021


Hi Bhaskar,
Perhaps you are looking for this:

approx(c(3,6,7),n=21)
$x
[1] 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7
2.8
[20] 2.9 3.0

$y
[1] 3.0 3.3 3.6 3.9 4.2 4.5 4.8 5.1 5.4 5.7 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7
6.8
[20] 6.9 7.0


This assumes that you are taking each value as a snapshot reading
rather than a cumulation of the values.

Jim

On Wed, Jun 9, 2021 at 4:33 AM Bhaskar Mitra <bhaskar.kolkata using gmail.com> wrote:
>
> 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 using 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.



More information about the R-help mailing list