0

I have daily measurements prec.d and periodic measurements prec.p. The periodic measurements (3-12 days apart) are roughly the sum of the daily measurements between the start and end dates, and I need to compare prec in the two data frames. I have so far manually created an index week that represents the time span of each periodic measurement, but it would be great to make week in a reproducible fashion.

data.frame prec.d

     day  week  prec
6/20/2013   1   0
6/21/2013   1   0
6/22/2013   1   0
6/23/2013   1   0
6/24/2013   1   41.402
6/25/2013   1   2.794
6/26/2013   1   6.096
6/27/2013   2   0.508
6/28/2013   2   0
6/29/2013   2   0
6/30/2013   2   2.54
7/1/2013    2   18.034
7/2/2013    2   4.064

And data.frame prec.p

  start         end   week  prec1      prec2        prec3
6/20/2013   6/26/2013   1   50.28   31.78042615 42.76461716
6/27/2013   7/2/2013    2   25.1    15.70964247 20.49507586

I would like to create the week field automatically, which spans from start to end in prec.p. The I can aggregate by week to make prec in both data frames match.

  • So far I manually created a factor to represent the time period to be aggregated, but id like this to be reproducible. – user3038792 Apr 25 '14 at 17:42

1 Answers1

0

Introduce YYYYWW field in both weekly and minute data, WW stands for week number, that will give you a common index. For example

x <- as.Date(runif(100)*100)
yyyyww <- strftime(x, format="%Y%U")
yyyyww 

Or take a look at package quantmod, if I remember correctly, it has functions for time frame conversion.

ndr
  • 1,427
  • 10
  • 11
  • thanks, but unless i'm missing something your example doesn't account for the variable time periods. I edited my explanation for clarity, and added example data. – user3038792 Apr 25 '14 at 17:41