[R] Simple rep() question duplicating times and dates.
Gustaf Rydevik
gustaf.rydevik at gmail.com
Wed Nov 5 16:14:19 CET 2008
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.
>
> 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
More information about the R-help
mailing list