There is a function here:
http://tolstoy.newcastle.edu.au/R/help/04/06/1430.html
that will facilitate this sort of construct:
a <- 1; b <- 2
list[b,a] <- list(a,b)
a; b # 2 1
On 6/9/06, David Hajage <dhajage at gmail.com>
wrote:> 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 at 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
>