[R] swap

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Fri Aug 22 15:57:34 CEST 2008

> Hello Richie,
> I would like to do three (or k) swap steps in each step just 2 ID 
> recursive swaping
> x <- 1:10
> swap <- function(x){
>   a <- sample(x,2)
>   x[x==a[1]] <- swap[2]
>   x[x==a[2]] <- swap[1]
>   return(x)
>   }
>   swap(swap(swap(x))) -> mix

I tried my best with a response before, but if you want a sensible answer 
you are going to have to try harder explaining what you really want.

What do you mean by 'swap step'?

If you want to swap the position of two elements in a vector (as I suspect 
you might) then which positions do you want swapping?  Do you specify them 
yourself (as inputs to the swap function perhaps), or should they be 
randomly generated?

If you provide more context (the rest of your code, what you are trying to 
achieve etc.) the help will be better.


Mathematical Sciences Unit


This message contains privileged and confidential inform...{{dropped:20}}

More information about the R-help mailing list