I want to create a data.frame of time and date for a year. I started with the idea of simply producing two vectors (time and date) The first part ( time) is easy. rep(1:24, 365) But how do I get a series of 24 dates for O1 January 2005 and repeat this to 31 December 2005. It should be easy but I don't see it. Thanks __________________________________________________________________ [[elided Yahoo spam]]
Gustaf Rydevik
2008-Nov-05 15:14 UTC
[R] Simple rep() question duplicating times and dates.
On Wed, Nov 5, 2008 at 4:02 PM, John Kane <jrkrideau at yahoo.ca> wrote:> > I want to create a data.frame of time and date for a year. I started with the idea of simply producing two vectors (time and date) > > The first part ( time) is easy. > rep(1:24, 365) > > But how do I get a series of 24 dates for O1 January 2005 and repeat this to 31 December 2005. > > It should be easy but I don't see it. > > ThanksHi John, ?Date leads you to (among other things) ?seq.Date. Something like this should work: time<-rep(1:24, 365) dates<-seq(as.Date("01012005",format="%d%m%Y"),as.Date("31122005",format="%d%m%Y"),by=1) TimeFrame<-data.frame(time) TimeFrame$dates<-rep(dates,each=24) Regards, Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik
Solveig Mimler
2008-Nov-06 12:06 UTC
[R] Simple rep() question duplicating times and dates.
Hi John, I had the same problem yesterday and solved it like following: seq(ISOdate(Year,Month,Day,Hour), by="hour", length=24*365) for example: seq(ISOdate(2005,1,1,0), by="hour", length=8760) Regards, Solveig EIFER Europäisches Institut für Energieforschung Institut européen de recherche sur l'énergie European Institute for Energy Research Solveig Mimler Sociologist M.A. Emmy-Noether-Straße 11 76131 Karlsruhe Tel: +49 721 6105 1351 Fax: +49 721 6105 1332 mailto: mimler@eifer.uka.de _________________________________________________ EIFER Europäisches Institut für Energieforschung, Electricité de France / Universität Karlsruhe (TH) EWIV Sitz der europäischen wirtschaftlichen Interessenvereinigung: Karlsruhe Handelsregister: Amtsgericht Karlsruhe HRA 4823 Vorsitzender des Aufsichtsrats: Prof. Dr.-Ing. RAINER REIMERT Geschäftsführer: Dr. FREDERIC BARON (Institutsleiter) _________________________________________________ This e-mail and any attachment is for authorized use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. _________________________________________________ Message: 27 Date: Wed, 5 Nov 2008 16:14:19 +0100 From: "Gustaf Rydevik" <gustaf.rydevik@gmail.com> Subject: Re: [R] Simple rep() question duplicating times and dates. To: jrkrideau@yahoo.ca Cc: R R-help <r-help@stat.math.ethz.ch> Message-ID: <45f568c70811050714n4711b370n3947a6c5c4fc393f@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Wed, Nov 5, 2008 at 4:02 PM, John Kane <jrkrideau@yahoo.ca> wrote:> > I want to create a data.frame of time and date for a year. I startedwith the idea of simply producing two vectors (time and date)> > The first part ( time) is easy. > rep(1:24, 365) > > But how do I get a series of 24 dates for O1 January 2005 and repeatthis to 31 December 2005.> > It should be easy but I don't see it. > > ThanksHi John, ?Date leads you to (among other things) ?seq.Date. Something like this should work: time<-rep(1:24, 365) dates<-seq(as.Date("01012005",format="%d%m%Y"),as.Date("31122005",format="%d%m%Y"),by=1) TimeFrame<-data.frame(time) TimeFrame$dates<-rep(dates,each=24) Regards, Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik ------------------------------ Message: 28 Date: Wed, 5 Nov 2008 07:30:31 -0800 (PST) From: John Kane <jrkrideau@yahoo.ca> Subject: Re: [R] Simple rep() question duplicating times and dates. To: Gustaf Rydevik <gustaf.rydevik@gmail.com> Cc: R R-help <r-help@stat.math.ethz.ch> Message-ID: <508556.15957.qm@web38406.mail.mud.yahoo.com> Content-Type: text/plain; charset=us-ascii I don't have R on this machine to try it but it looks good to me. I had even got as far as seq() but completely missed the use of "each". Thanks very much. --- On Wed, 11/5/08, Gustaf Rydevik <gustaf.rydevik@gmail.com> wrote:> From: Gustaf Rydevik <gustaf.rydevik@gmail.com> > Subject: Re: [R] Simple rep() question duplicating times and dates.> Cc: "R R-help" <r-help@stat.math.ethz.ch> > Received: Wednesday, November 5, 2008, 10:14 AM > On Wed, Nov 5, 2008 at 4:02 PM, John Kane> > > > I want to create a data.frame of time and date for a > year. I started with the idea of simply producing two > vectors (time and date) > > > > The first part ( time) is easy. > > rep(1:24, 365) > > > > But how do I get a series of 24 dates for O1 January > 2005 and repeat this to 31 December 2005. > > > > It should be easy but I don't see it. > > > > Thanks > > > Hi John, > > ?Date leads you to (among other things) ?seq.Date. > > Something like this should work: > > time<-rep(1:24, 365) >dates<-seq(as.Date("01012005",format="%d%m%Y"),as.Date("31122005",format="%d%m%Y"),by=1)> TimeFrame<-data.frame(time) > TimeFrame$dates<-rep(dates,each=24) > > > Regards, > Gustaf > -- > Gustaf Rydevik, M.Sci. > tel: +46(0)703 051 451 > address:Essingetorget 40,112 66 Stockholm, SE > skype:gustaf_rydevik[[alternative HTML version deleted]]