zowiti at ncst.go.ke
2010-Apr-21 03:16 UTC
[R] Converting daily data series to monthly series
Hi Users, I have daily series of data from 1962 - 2000, with the data for February 29th in leap years excluded, leaving 365 daily values for each year. I wish to convert the daily series to monthly series. How can I do this using the zoo package or any other package? Thanks ZABLONE OWITI GRADUATE STUDENT Nanjing University of Information, Science and Technology College of International Education Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China Tel: +86-25-58731402 Fax: +86-25-58731456 Mob. 15077895632 Website: www.nuist.edu.cn =================================================== [[alternative HTML version deleted]]
Gabor Grothendieck
2010-Apr-21 03:44 UTC
[R] Converting daily data series to monthly series
There is a monthly aggregation of daily data example in the zoo-quickref vignette: vignette("zoo-quickref") and there are also relevant examples using aggregate.zoo or duplicated in the example section of ?aggregate.zoo On Tue, Apr 20, 2010 at 11:16 PM, zowiti at ncst.go.ke <zowiti at ncst.go.ke> wrote:> Hi Users, > I have daily series of data from 1962 - 2000, with ?the data for February > 29th in leap years ?excluded, leaving 365 daily values for each year. I > wish to convert the daily series to monthly series. How can I do this using > the zoo package or any other package? > > Thanks > > ZABLONE OWITI > ?GRADUATE STUDENT > Nanjing University of Information, Science and Technology > College of International Education > Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China > Tel: +86-25-58731402 > Fax: +86-25-58731456 > Mob. 15077895632 > Website: www.nuist.edu.cn > ===================================================> > > ? ? ? ?[[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. >
> -----Mensaje original----- > De: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] En nombre de zowiti at ncst.go.ke > Enviado el: mi?rcoles, 21 de abril de 2010 5:16 > Para: r-help at r-project.org > Asunto: [R] Converting daily data series to monthly series > > Hi Users, > I have daily series of data from 1962 - 2000, with the data > for February 29th in leap years excluded, leaving 365 daily > values for each year. I wish to convert the daily series to > monthly series. How can I do this using the zoo package or > any other package? > > Thanks > > ZABLONE OWITI > GRADUATE STUDENT > Nanjing University of Information, Science and Technology > College of International EducationLet df be your dataframe, #In case you have to format your data as date before setting the montth df$date <- as.Date(df$date, "%d/%m/%Y") #Getting year, month and week from your correctly formatted date df$Year <- as.numeric(format(df$date, "%Y")) #Year df$Month <- as.numeric(format(df$date, "%m")) #Month df$Week <- as.numeric(format(df$date, "%W")) +1 #Week ____________________________________________________________________________________ Dr. Rub?n Roa-Ureta AZTI - Tecnalia / Marine Research Unit Txatxarramendi Ugartea z/g 48395 Sukarrieta (Bizkaia) SPAIN
zowiti at ncst.go.ke
2010-Apr-21 06:03 UTC
[R] Converting daily data series to monthly series
Thanks Gabor, I have got the idear how to aggregate the daily data into monthly data using the zoo package. However, as I indicated earlier, in the series I am analysing, 29th February of leap years are excluded (so as to have 365 days in each year). How do I coerce(force) the the aggregate command to only sum 28-days in February for all the years. Thanks ZABLONE OWITI GRADUATE STUDENT Nanjing University of Information, Science and Technology College of International Education Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China Tel: +86-25-58731402 Fax: +86-25-58731456 Mob. 15077895632 Website: www.nuist.edu.cn =================================================== ---------------------------------------- From: "Gabor Grothendieck" <ggrothendieck@gmail.com> Sent: Wednesday, April 21, 2010 11:46 AM To: zowiti@ncst.go.ke Subject: Re: [R] Converting daily data series to monthly series There is a monthly aggregation of daily data example in the zoo-quickref vignette: vignette("zoo-quickref") and there are also relevant examples using aggregate.zoo or duplicated in the example section of ?aggregate.zoo On Tue, Apr 20, 2010 at 11:16 PM, zowiti@ncst.go.ke wrote:> Hi Users, > I have daily series of data from 1962 - 2000, with the data forFebruary> 29th in leap years excluded, leaving 365 daily values for each year. I > wish to convert the daily series to monthly series. How can I do thisusing> the zoo package or any other package? > > Thanks > > ZABLONE OWITI > GRADUATE STUDENT > Nanjing University of Information, Science and Technology > College of International Education > Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China > Tel: +86-25-58731402 > Fax: +86-25-58731456 > Mob. 15077895632 > Website: www.nuist.edu.cn > ===================================================> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Gabor Grothendieck
2010-Apr-21 10:28 UTC
[R] Converting daily data series to monthly series
If you only have 28 days in Feb in your series then that is what will be summed if you follow those examples. If you mean that your series does include Feb 29th but you want to exclude it from the aggregates then just remove the Feb 29th points first and work with the reduced series: library(zoo) x <- zooreg(1:366, start = as.Date("2000-01-01")) ix <- format(time(x), "%m-%d") != "02-29" x0 <- x[ix] aggregate(x0, as.yearmon, sum) On Wed, Apr 21, 2010 at 2:03 AM, zowiti at ncst.go.ke <zowiti at ncst.go.ke> wrote:> Thanks? Gabor, > I have got the idear how to aggregate the daily data into monthly data using > the zoo package. However, as I indicated earlier, in the series I am > analysing,?29th February of leap years are excluded (so as to have 365 days > in each year). How do I coerce(force) the the aggregate command to only? sum > 28-days in February for all the years. > > Thanks > > ZABLONE OWITI > GRADUATE STUDENT > Nanjing University of Information, Science and Technology > College of International Education > Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China > Tel: +86-25-58731402 > Fax: +86-25-58731456 > Mob. 15077895632 > Website: www.nuist.edu.cn > ===================================================> > > ________________________________ > From: "Gabor Grothendieck" <ggrothendieck at gmail.com> > Sent: Wednesday, April 21, 2010 11:46 AM > To: zowiti at ncst.go.ke > Subject: Re: [R] Converting daily data series to monthly series > > There is a monthly aggregation of daily data example in the > zoo-quickref vignette: > > vignette("zoo-quickref") > > and there are also relevant examples using aggregate.zoo or duplicated > in the example section of ?aggregate.zoo > > > On Tue, Apr 20, 2010 at 11:16 PM, zowiti at ncst.go.ke wrote: >> Hi Users, >> I have daily series of data from 1962 - 2000, with ?the data for February >> 29th in leap years ?excluded, leaving 365 daily values for each year. I >> wish to convert the daily series to monthly series. How can I do this >> using >> the zoo package or any other package? >> >> Thanks >> >> ZABLONE OWITI >> ?GRADUATE STUDENT >> Nanjing University of Information, Science and Technology >> College of International Education >> Add: 219 Ning Liu Rd, Nanjing, Jiangsu, 21004, P.R. China >> Tel: +86-25-58731402 >> Fax: +86-25-58731456 >> Mob. 15077895632 >> Website: www.nuist.edu.cn >> ===================================================>> >> >> ? ? ? ?[[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. >> > >