# [R] leap year and order function

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Jan 31 06:16:16 CET 2011

> 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-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Bobby Lee
Sent: Monday, 31 January 2011 2:23 PM
To: R-help at 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 at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help