Hello :) I wanted to right an expression to check when x and y have the same sign and I wrote the following: if ((x<0 && y<0) || (x>0 && y>0)) which looks pretty ugly to me. Can you please suggest me a better way for that? Regards Alex
Try this: !diff(sign(c(x, y))) On Mon, Jan 24, 2011 at 4:18 PM, Alaios <alaios@yahoo.com> wrote:> Hello :) > I wanted to right an expression to check when x and y have the same sign > and I wrote the following: > > if ((x<0 && y<0) || (x>0 && y>0)) > > which looks pretty ugly to me. > > Can you please suggest me a better way for that? > > Regards > Alex > > ______________________________________________ > 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 [[alternative HTML version deleted]]
On Monday, January 24, 2011 07:18:03 pm Alaios wrote:> Hello :) > I wanted to right an expression to check when x and y have the same sign > and I wrote the following: > > if ((x<0 && y<0) || (x>0 && y>0)) > > which looks pretty ugly to me. > > Can you please suggest me a better way for that? > > Regards > Alex > > ______________________________________________ > 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. >if( sign( x ) == sign( y ) )
if (x*y>0) {...} On Mon, Jan 24, 2011 at 1:27 PM, Rainer Schuermann <Rainer.Schuermann at gmx.net> wrote:> On Monday, January 24, 2011 07:18:03 pm Alaios wrote: >> Hello :) >> I wanted to right an expression to check when x and y have the same sign >> and I wrote the following: >> >> ?if ((x<0 && y<0) || (x>0 && y>0)) >> >> which looks pretty ugly to me. >> >> Can you please suggest me a better way for that? >> >> Regards >> Alex >> >> ______________________________________________ >> 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. >> > > > if( sign( x ) == sign( y ) ) > > ______________________________________________ > 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. >