After removing the leap day from my time series, I used format = %j
to get the day of year DoY
values. However, the last DoY value was still 366 rather than 365 because the DoY
= 60 gets skipped which is where 1996-02-29
was. How can I get the correct day of year after removing the leap day from my time series?
similar StackOverflow question here
Example:
df <- data.frame(matrix(ncol = 2, nrow = 366))
x <- c("date", "DoY")
colnames(df) <- x
start = as.Date("1996-01-01")
end = as.Date("1996-12-31")
df$date <- seq.Date(start,end,1)
remove_leap <- as.Date(c("1996-02-29"))
df <- df[!df$date %in% remove_leap,]
df$DoY <- strftime(df$date, format = "%j") #this formats the date to DoY values but still *sees* the leap day giving a max DoY = 366 rather than 365
df$DoY <- as.numeric(df$DoY)