Hi: There is an additional proviso:
If the year is divisible by 100, then the next test is whether it's divisible by 400. If both conditions are met, then the century year is a leap year. Hence, 2000 was a leap year because it is divisible by 400, but 2100, 2200 and 2300 will not be. For Perl and Ruby code, see http://feb29.leapyearday.com/freecode.html The 'correct' code is in a link associated with the Note below the first paragraph. HTH, Dennis On Sun, Jan 30, 2011 at 9:16 PM, <bill.venab...@csiro.au> wrote: > > yearLength <- function(year) 365 + (year %% 4 == 0) > > > > yearLength(1948:2010) > [1] 366 365 365 365 366 365 365 365 366 365 365 365 366 365 365 365 366 > 365 365 365 366 > [22] 365 365 365 366 365 365 365 366 365 365 365 366 365 365 365 366 365 > 365 365 366 365 > [43] 365 365 366 365 365 365 366 365 365 365 366 365 365 365 366 365 365 > 365 366 365 365 > > > > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Bobby Lee > Sent: Monday, 31 January 2011 2:23 PM > To: R-help@r-project.org > Subject: [R] leap year and order function > > im trying to write a for loop so that every leap year, the number of days > becomes to 366 instead of 365. could someone help me out? > and also, this set of data has 99.99s I set all the 99.99 ==NA. > however, when im doing the order function to find the max value of that > year, it still reads 99.99 as the max value. > Thank you very much > > maxday <- matrix(NA,63,5) > > for (a in 1948:2010){ > > maxday[,1]<-1948:2010 > yearly<-na.omit(dat.mat[dat.mat[,1]==a,]) > > maxday[a-1947,2]<-yearly[order(yearly[,4])[*365*],2] > maxday[a-1947,3]<-yearly[order(yearly[,4])[*365*],3] > > > maxday[63,2]<-yearly[order(yearly[,4])[127],2] > maxday[63,3]<-yearly[order(yearly[,4])[127],3] > maxday[a-1947,4]<-max(yearly[,4]) > maxday[,5]<-len[,2] > } > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.