Thursday, October 22, 2009

Leap years

A quick function that when provided a numeric vector of years returns a boolean vector where TRUE == Leap year.

is.leapyear=function(year){
#http://en.wikipedia.org/wiki/Leap_year
return(((year %% 4 == 0) & (year %% 100 != 0)) | (year %% 400 == 0))
}

1 comment:

James said...

Alternatively,

format(as.POSIXct(paste(year,"-03-01",sep=""))-1,"%d")=="29"