I am trying to create a Julian date from a POSIXct
date that is 1-365 for each 365 day period.
More specifically, with the dates below covering a 2 year period starting 2013-2-15, I have have used the julian()
function to create a new Julian date.
DF <- data.frame(Date = seq(as.POSIXct("2013-2-15"), by = "day", length.out = 730))
DF$Julian = 1+(as.numeric(julian(DF$Date, origin = as.POSIXct("2013-2-15"))))
Date Julian
1 2013-02-15 1
2 2013-02-16 2
3 2013-02-17 3
4 2013-02-18 4
5 2013-02-19 5
6 2013-02-20 6
> tail(DF)
Date Julian
725 2015-02-09 725
726 2015-02-10 726
727 2015-02-11 727
728 2015-02-12 728
729 2015-02-13 729
730 2015-02-14 730
However, as seen in the tail()
above, the Julian date spans to 730, the entire 2 years. I want the julian day to be scaled relative to start day (as is done here), but no greater than 365. I want 15-Feb to be 1 and and Feb 14th or the following year is 365. In essence, the Julian day should start over at 1 for each 365 day period.
Thanks in advance!
EDIT/ADDITION If, for example I want to calculate the Julian date with a specific origin, I can use the following code:
DF$JulianNew <- as.integer(julian(DF$Date,origin=as.Date("2013-2-16")))%%365L+1L
However, as seen in the head
Date Julian JulianNew
1 2013-02-15 1 1
2 2013-02-16 2 1
3 2013-02-17 3 2
4 2013-02-18 4 3
5 2013-02-19 5 4
6 2013-02-20 6 5
The date 2013-02-15 is marked as being within one day of the origin of 2013-02-16. How can ensure that dates in the past are not included and that the search goes only forward?