Reputation: 21
I have .nc data file which contains daily temperature data for complete period in a single column.Time variable have 365 days calendar(no-leap year). I want to calculate monthly/ annually mean/max/min values.How to use as.date for 365 days calander?
d<- seq(as.Date("2071-01-01"), as.Date("2099-12-31"),1)
The above code create the sequence but it includes the leap year also.
Upvotes: 1
Views: 1692
Reputation: 1490
Not sure whether you want to remove all the leap years or remove just the feb 29s
x<-seq(as.Date("2011-01-01"),as.Date("2016-03-01"),by="day")
is.leapyear=function(year) return(((year %% 4 == 0) & (year %% 100 != 0)) | (year %% 400 == 0))
#remove all dates in leap years
x[!is.leapyear(as.integer(format(x, "%Y")))]
#remove all feb 29s
x[format(x,"%m-%d") != "02-29"]
Upvotes: 1
Reputation: 1619
I'am not sure if it is the nicest way of doing it. I would remove all 29th of february's from the sequence.
d <- d[!grepl(x = d, pattern = "-02-29$")]
Upvotes: 2