Re: [R] conditional IF with AND
Thank you all for your replies. This is all very useful information for me! Ted, thank you very much for the extra explanation and example. Many thanks, rcoder Ted.Harding-2 wrote: > > 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] , a[x,y] ) >> >> 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 > > The 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( ()&() ) { > > } > > 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) <[EMAIL PROTECTED]> > Fax-to-email: +44 (0)870 094 0861 > Date: 13-Aug-08 Time: 19:33:53 > -- XFMail -- > > __ > 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. > > -- View this message in context: http://www.nabble.com/conditional-IF-with-AND-tp18966890p18970101.html Sent from the R help mailing list archive at Nabble.com. __ 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.
Re: [R] conditional IF with AND
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] , a[x,y] ) > > 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 The 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( ()&() ) { } 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) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 13-Aug-08 Time: 19:33:53 -- XFMail -- __ 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.
Re: [R] conditional IF with AND
See: ?`&` On Wed, Aug 13, 2008 at 1:45 PM, rcoder <[EMAIL PROTECTED]> 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] , a[x,y] ) > > 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@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 __ 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.
Re: [R] conditional IF with AND
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] , a[x,y] ) 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 __ 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] conditional IF with AND
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] , a[x,y] ) 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@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.