Hello, just a simple question How can I do to invert the sign of a number? (for example: -4 to 4, 2 to -2 and so on..) I was looking for a specific function in R but I didn't found it... thank you Francesco -- View this message in context: http://www.nabble.com/Invert-the-sign-of-a-number-tp26110267p26110267.html Sent from the R help mailing list archive at Nabble.com.
x <- -x On Thu, Oct 29, 2009 at 6:06 AM, Fran100681 <franaruto at hotmail.it> wrote:> > Hello, > > just a simple question > > How can I do to invert the sign of a number? (for example: -4 to 4, 2 to -2 > and so on..) > I was looking for a specific function in R but I didn't found it... > thank you > > Francesco > -- > View this message in context: http://www.nabble.com/Invert-the-sign-of-a-number-tp26110267p26110267.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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On 29/10/2009 6:06 AM, Fran100681 wrote:> Hello, > > just a simple question > > How can I do to invert the sign of a number? (for example: -4 to 4, 2 to -2 > and so on..) > I was looking for a specific function in R but I didn't found it... > thank youYou want the unary - operator. For example, -x has opposite signs to x. Even --4 will work to give 4, but it will scare C programmers, so it's probably best to use parentheses: -(-4) Duncan Murdoch
Fran100681 <franaruto at hotmail.it> wrote> >just a simple question > >How can I do to invert the sign of a number? (for example: -4 to 4, 2 to -2 >and so on..) >I was looking for a specific function in R but I didn't found it... >thank you >Is there something wrong with *-1 ? Peter Peter L. Flom, PhD Statistical Consultant Website: www DOT peterflomconsulting DOT com Writing; http://www.associatedcontent.com/user/582880/peter_flom.html Twitter: @peterflom