Hi everyone, I'm trying to create an "if" conditional statement with two conditions, whereby the statement is true when condition 1 AND condition 2 are met: code structure: if ?AND? (a[x,y] <condition1>, a[x,y] <condition2>) I've trawled through the help files, but I cannot find an example of the syntax for incorporating an AND in a conditional IF statement. Thanks, rcoder -- View this message in context: http://www.nabble.com/conditional-IF-with-AND-tp18966890p18966890.html Sent from the R help mailing list archive at Nabble.com.
if(cond1 && cond2) { ... } rcoder wrote:> Hi everyone, > > I'm trying to create an "if" conditional statement with two conditions, > whereby the statement is true when condition 1 AND condition 2 are met: > > code structure: > if ?AND? (a[x,y] <condition1>, a[x,y] <condition2>) > > I've trawled through the help files, but I cannot find an example of the > syntax for incorporating an AND in a conditional IF statement. > > Thanks, > > rcoder
See: ?`&` On Wed, Aug 13, 2008 at 1:45 PM, rcoder <mpdotbook at gmail.com> wrote:> > Hi everyone, > > I'm trying to create an "if" conditional statement with two conditions, > whereby the statement is true when condition 1 AND condition 2 are met: > > code structure: > if ?AND? (a[x,y] <condition1>, a[x,y] <condition2>) > > I've trawled through the help files, but I cannot find an example of the > syntax for incorporating an AND in a conditional IF statement. > > Thanks, > > rcoder > -- > View this message in context: http://www.nabble.com/conditional-IF-with-AND-tp18966890p18966890.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
On 13-Aug-08 16:45:27, rcoder wrote:> Hi everyone, > I'm trying to create an "if" conditional statement with two conditions, > whereby the statement is true when condition 1 AND condition 2 are met: > > code structure: > if ?AND? (a[x,y] <condition1>, a[x,y] <condition2>) > > I've trawled through the help files, but I cannot find an example of > the syntax for incorporating an AND in a conditional IF statement. > > Thanks, > rcoderThe basic structure of an 'if' statement (from ?"if" -- don't forget the ".." for certain keywords such as "if") is: if(cond) expr What is not explained in the ?"if" help is that 'cond' may be any expression that evaluates to a logical TRUE or FALSE. Hence you can build 'cond' to suit your purpose. Therefore: if( (<condition 1 on a[x,y]>)&(<condition 2 on a[x,y]>) ) { <whatever you want to do if (cond1 AND cond2 ) is TRUE> } Example: if( (a[x,y]>1.0)&(a[x,y]<2.0) ){ print("Between 1 and 2") } Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 13-Aug-08 Time: 19:33:53 ------------------------------ XFMail ------------------------------