An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110130/69559671/attachment.pl>
leap year and order function
4 messages · Bobby Lee, Bill Venables, Dennis Murphy +1 more
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]
}
______________________________________________
R-help at 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110131/8a4b1f23/attachment.pl>
Dear All, I've always used this code: year=c(1948:1953,2000,2100,2200,2300) numdays=ifelse((year%%4==0 & year%%100!=0) | year%%400==0,366,365)
numdays
[1] 366 365 365 365 366 365 366 365 365 365 Toby
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Dennis Murphy [djmuser at gmail.com]
Sent: 31 January 2011 11:51
To: Bill.Venables at csiro.au
Cc: R-help at r-project.org
Subject: Re: [R] leap year and order function
Sent: 31 January 2011 11:51
To: Bill.Venables at csiro.au
Cc: R-help at r-project.org
Subject: Re: [R] leap year and order function
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.Venables at 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-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 > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.