Try this. First we read in the data. In reality you would use
the commented out read line. Then use chron to convert
the times to chron dates and as.yearmon from zoo to convert
them to year/months. Finally aggregate and sort.
> Lines <- "IDtime y
+ 12/01/20084
+ 12/09
I had trouble getting my output to look like yours until I realized
that you did not want "to sum up the weekly data to the monthly level"
but rather to sum up to the monthly *and* ID level.
> dftag<-aggregate(dft$y, list(ID=dft$ID, Month=as.yearmon(dft$time,
"%m/%d/%Y")), FUN=sum)
# in Mo
f liujb
Sent: Tuesday, 13 January 2009 8:58
To: r-help@r-project.org
Subject: [R] roll weekly data to monthly level
Dear R users:
I have a data set that looks something like this:
IDtime y
12/01/20084
12/09/200812
19/01/20088
21/06/20083
23/01
Dear R users:
I have a data set that looks something like this:
IDtime y
12/01/20084
12/09/200812
19/01/20088
21/06/20083
23/01/20084
23/09/20089
26/03/20084
31/02/20083
31/10/20088
32/02/20087
32/10
4 matches
Mail list logo