Re: [R] Problem with Julian function

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri 16 Jun 2006 - 00:04:08 EST

This looks like a bug to me too although its one off rather than two off since julian uses origin 0, not 1, e.g.

> julian(1,1,2000, origin = c(1,1,2000))
[1] 0

Here is a workaround that seems to work ok and uses origin 1:

> as.numeric(format(as.Date(ymd), "%j")) # ymd from your post
 [1] 139 139 139 140 140 140 140 141 141 141

On 6/15/06, Devred, Emmanuel <DevredE@mar.dfo-mpo.gc.ca> wrote:
> Dear all,
>
> I have a problem with the function Julian, may be a bug in the function ?
> Here is a vector of character, which represents dates (May 18 to May 20
> 2000):
>
> > amj <- c("2000-05-18","2000-05-18","2000-05-18","2000-05-19","2000-05-19"
> > ,"2000-05-19", "2000-05-19", "2000-05-20", "2000-05-20", "2000-05-20")
>
> I load the date and chron libraries, I define the vector of character as a
> date variable using the dates function:
>
> > ymd <- dates(amj,format=c(dates="y-m-d"),origin=c(month=1,
> day=1,year=2000))
>
> Then when I apply the Julian function:
>
> > julian(months(ymd),days(ymd),years(ymd),origin=c(month = 1, day = 1, year
> = as.numeric(years(ymd[1]))))
>
> I get the following result:
>
> [1] 137 137 137 138 138 138 138 139 139 139
>
> However, when I check on the calendar, the dates I have correspond to the
> 139th, 140th and 141st days of the year (there is a two days shift because
> it is a leap year, for other years I have a one day shift).
> I tried the default origin when I use the dates function but I get the same
> results.
>
> Did anyone have this problem before ? I would appreciate some help,
>
> Thank you very much,
>
> Emmanuel
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jun 16 01:19:19 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 16 Jun 2006 - 02:12:53 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.