[R] reverse variables

From: David Hajage <dhajage_at_gmail.com>
Date: Sat 10 Jun 2006 - 01:07:04 EST


Hello useRs,

Is there a way to reverse values of 2 variables (like with the language Python) ? :

a <- 1
b <- 2

a, b <- b, a

More specifically, I have a data frame :

   famnum generation germain1 germain2 fa mo ptpn1 ptpn2 drb11 drb12

       1          2      200      201 101 102     1     1     1     1
       2          2      200      201 101 102     0     1     1     1
       3          2      200      201 101 102     1     0     1     1

...

I don't want "0" in the seventh column, so I would like to have :

   famnum generation germain1 germain2 fa mo ptpn1 ptpn2 drb11 drb12

       1          2      200      201 101 102     1     1     1     1
       2          2      201      200 101 102     1     0     1     1
       3          2      200      201 101 102     1     0     1     1

...

I thought that a code like this would work :

if (ptpn1 == 0 & ptpn2 == 1)
  {
    germain1, germain2 <- germain2, germain1     ptpn1, ptpn2 <- ptpn2, ptpn1
    drb11, drb12 <- drb12n, drb11
  }

But R is not Python... Is there a way to do it easyly ?

Thank you.

-- 
David

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Jun 10 01:14:05 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 11 Jun 2006 - 05:34:53 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.