[R] Problem with Julian function
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jun 15 16:04:08 CEST 2006
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 at 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 at 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
>
More information about the R-help
mailing list