FInding date gaps in R

后端 未结 1 633
深忆病人
深忆病人 2021-01-28 00:42

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,         


        
1条回答
  •  清酒与你
    2021-01-28 01:10

    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
    

    0 讨论(0)
提交回复
热议问题