Remove February 29 and December 31 from date vector

  Kiến thức lập trình

I have a date vector as follows:

obs.y1 <- '1971-1-1'
obs.y2 <- '2000-12-31'
obs.ymd <- seq.Date(from=as.Date(obs.y1), to=as.Date(obs.y2),
                    by='days')

I tried to remove feb 29 and dec 31:

#obs.ymd <- rep(obs.ymd, each=1)
obs.ymd <- obs.ymd[!(format(obs.ymd, '%m %d')=='02 29')]
obs.ymd <- obs.ymd[!(format(obs.ymd, '%m %d')=='12 31')]
obs.ymd <- format(obs.ymd, '%Y %m %d')
obs.ymd <- apply(do.call(rbind, strsplit(obs.ymd, ' ')), 2, as.integer)

My final output should be 10890 timesteps. However, I keep getting 10920 timesteps. The above code does not remove some dec 31s.

LEAVE A COMMENT