I don't think the text is giving the correct reasoning for why we do what we are doing. I'm pretty sure I wrote that original code but not the indexing part in code or text. The origin day is 01 January 2011 so the extracted day is 01. The Julian day for this is also 01. If we need to cover Julian day 05 (which is the 5th of January), we cant add origin+Julian day because 1+5 is 6 or January 06, 2011, we have to add origin+JD-1 to get the correct day January 05 2011.
The explanation of zero-based indexing isn't wrong, but I think its application here is wrong. Can someone confirm this for me?
http://data-lessons.github.io/NEON-R-Spatial-Raster//R/Extract-NDVI-From-Rasters-In-R/
~line 231, code chunk: {r convert-jd}
CODE:
#create a date column; -1 added because origin is the 1st and indexing begins at 0.
#If not -1, 01/01/2011 + 5 = 01/06/2011 which is Julian day 6, not 5.
avg_NDVI_HARV$Date<- origin + (avg_NDVI_HARV$julianDay-1)
TEXT:
Zero-Based Indexing
Note that when converting our character formatted Julian Day values to dates,
we subtracted one as follows:
avg_NDVI_HARV$Date <- origin + (avg_NDVI_HARV$julianDay-1)
This is because R
stores Julian days using 0-based indexing. That is the first
value is 0, rather than 1. Thus Julian Day 1, is stored as 0, Julian day 2 is
stored as 1, and so on.