[R] How to improve a function converting year, day of year, decimal hour into date ?

Gabor Grothendieck ggrothendieck at gmail.com
Tue Nov 20 13:19:33 CET 2007


library(chron)
chron(paste("1/1/", year, sep = "")) + julday + hour/24

That produces a chron, i.e. dates/times class datetime.  If you want
it as a string use format(...above expression...)    See the help desk
article in R News 4/1.

On Nov 20, 2007 6:53 AM, Ptit_Bleu <ptit_bleu at yahoo.fr> wrote:
>
> Hi,
>
> I would like to "build" a date from a year, a day of the year and a decimal
> hour.
> Ex : reconst_date(2007,324,12.50) gives "2007-11-20 12:30:0"
>
> The following function is doing this job but I would like to know if there
> is a function which directly converts the decimal hours into
> hours:minutes:secondes ?
>
> Thanks for your help,
> Have a nice day,
> Ptit Bleu.
>
> --------------------
>
> reconst_date<-function(annee, jour, heured) {
> str_anneejour<-paste(annee,jour,sep=" ")
> str_anneemoisjour<-strptime(str_anneejour, "%Y %j")
> heure<-trunc(heured)
> minute<-trunc((heured-heure)*60)
> seconde<-((heured-heure)*60-minute)*60
> seq_dateR<-paste(str_anneemoisjour,"
> ",heure,":",minute,":",round(seconde),sep="")
> return(seq_dateR)
> }
> --
> View this message in context: http://www.nabble.com/How-to-improve-a-function-converting-year%2Cday-of-year%2Cdecimal-hour-into-date---tf4843032.html#a13855563
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list