Hi, I'm trying to create a function, jim(p) which varies depending on whether the value of p is odd or even. I was trying to use th eIf function, but i cant work out a formula to work out if p is odd or even. Thanks, Dave __________________________________________________ Yahoo! Plus For a better Internet experience http://www.yahoo.co.uk/btoffer
Dave Caccace wrote:> Hi, > I'm trying to create a function, jim(p) which varies > depending on whether the value of p is odd or even. I > was trying to use th eIf function, but i cant work out > a formula to work out if p is odd or even. > Thanks, > Daveif(p %% 2) "odd" else "even" Uwe Ligges
Or if you are very lazy there is is.odd() and is.even() in library sma. -----Original Message----- From: Uwe Ligges [mailto:ligges at statistik.uni-dortmund.de] Sent: Sunday, April 06, 2003 8:36 PM To: Dave Caccace Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Odd and Even Dave Caccace wrote:> Hi, > I'm trying to create a function, jim(p) which varies > depending on whether the value of p is odd or even. I > was trying to use th eIf function, but i cant work out > a formula to work out if p is odd or even. > Thanks, > Daveif(p %% 2) "odd" else "even" Uwe Ligges ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Thank you for you previous help :) I now need ot know how i can name a specific operation inside a function. i am using the if(cond){}else{} construction and would like to name it. However if i do assign a name to it and then call it later onm in the function, it is not recognised. does any one have any idea why? Thank you, Dave
Functions can be defined within (i.e. local to) functions. If you are more specific about what you did, it would be easier for others to help. Spencer Graves Dave Caccace wrote:> Thank you for you previous help :) > > I now need ot know how i can name a specific operation > inside a function. i am using the if(cond){}else{} > construction and would like to name it. However if i > do assign a name to it and then call it later onm in > the function, it is not recognised. does any one have > any idea why? > Thank you, > Dave > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help