Reputation: 35
I am using R and have a vector of dates as Day of Year (DOY) in which some days are missing. I want to find where these missing days are.
DOY <- c(1,2,5,6,7,10,15,16,17)
I want an output which tells me that missing days are between day:
2 to 5
7 to 10
10 to 15
(Or the indices of these locations)
Upvotes: 0
Views: 2106
Reputation: 263382
rDOY <- range(DOY);
rnDOY <- seq(rDOY[1],rDOY[2])
rnDOY[!rnDOY %in% DOY]
[1] 3 4 8 9 11 12 13 14
If instead you don't want the mssing days and do wnat the beginnings and ends of the missing items:
> DOY[ diff(DOY)!=1]
[1] 2 7 10
> DOY[-1] [ diff(DOY)!=1]
[1] 5 10 15
Upvotes: 4