CALEF ALEJANDRO RODRIGUEZ CUEVAS
2012-Sep-27 03:03 UTC
[R] How does "apply.monthly" function works (xts package)
Hi everybody. I use to work with monthly data, however this is my first time working with weekly data. I have 4 data bases with monthly data and 1 with weekly data, so I want to convert my weekly to monthly data in order to have the same periodicity in all of them. I've read that package xts can help me with this issue, so I have done the following script: *ini_week<-as.Date("2010-09-19") final_week<-seq(ini_week, length.out=104, by = "1 week") vts<-read.csv("C:/DATA.csv",header = TRUE) vts<-vts[,2] wvts<-xts(vts, order.by=final_week) mes<-apply.monthly(wvts,sum) *A portion of the result is this one: [,1] 2010-09-26 2.9 2010-10-31 8.5 2010-11-28 5.8 2010-12-26 5.5 2011-01-30 7.5 .... It seem to be quite well however I have still the question about how does it work...I mean, for example the last week of September 2010 goes from * "2010-09-26"* to *"2010-10-03"* with a total number of sales of that week of 1.5 USD millions...so, how does R assign the portion of those 1.5 USD millions to the last days of September and the first 2 days of October? Thanks a lot in advance. Regards. [[alternative HTML version deleted]]
R. Michael Weylandt
2012-Sep-29 15:30 UTC
[R] How does "apply.monthly" function works (xts package)
On Thu, Sep 27, 2012 at 4:03 AM, CALEF ALEJANDRO RODRIGUEZ CUEVAS <alejandro.rodriguez.cuevas at gmail.com> wrote:> Hi everybody. > > I use to work with monthly data, however this is my first time working with > weekly data. > > I have 4 data bases with monthly data and 1 with weekly data, so I want to > convert my weekly to monthly data in order to have the same periodicity in > all of them. > > I've read that package xts can help me with this issue, so I have done the > following script: > > *ini_week<-as.Date("2010-09-19") > > final_week<-seq(ini_week, length.out=104, by = "1 week") > > vts<-read.csv("C:/DATA.csv",header = TRUE) > vts<-vts[,2] > > wvts<-xts(vts, order.by=final_week) > mes<-apply.monthly(wvts,sum) > > *A portion of the result is this one: > > [,1] > 2010-09-26 2.9 > 2010-10-31 8.5 > 2010-11-28 5.8 > 2010-12-26 5.5 > 2011-01-30 7.5 > .... > > It seem to be quite well however I have still the question about how does > it work...I mean, for example the last week of September 2010 goes from * > "2010-09-26"* to *"2010-10-03"* with a total number of sales of that week > of 1.5 USD millions...so, how does R assign the portion of those 1.5 USD > millions to the last days of September and the first 2 days of October?It doesn't. The vector is divided into non-overlapping intervals by the endpoints() function and they are summed separately. Read through ?endpoints Michael> > Thanks a lot in advance. > > Regards. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.
Seemingly Similar Threads
- [LLVMdev] Implementing llvm.atomic.cmp.swap.i32 on PowerPC
- dtrace overhead and proper measuring technique
- [LLVMdev] Instruction MVT::ValueTypes
- [LLVMdev] [llvm-commits] [llvm] r79731 - /llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
- [LLVMdev] MemRefs in a Load Instruction