Is this what you want: > swap <- function(z){ + a <- sample(length(z), 2) + z[a] <- z[rev(a)] + z + } > swap(1:10) [1] 2 1 3 4 5 6 7 8 9 10 > > swap(1:10) [1] 5 2 3 4 1 6 7 8 9 10 > swap(1:10) [1] 8 2 3 4 5 6 7 1 9 10 > swap(1:10) [1] 2 1 3 4 5 6 7 8 9 10 > swap(1:10) [1] 4 2 3 1 5 6 7 8 9 10 > swap(swap(swap(1:10))) [1] 8 10 3 5 4 6 7 1 9 2 > swap(swap(swap(1:10))) [1] 8 2 7 4 5 6 3 10 9 1 >
On Fri, Aug 22, 2008 at 8:57 AM, amor Gandhi <[EMAIL PROTECTED]> wrote: > 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 > > Is this possible? > Thanks you in advance! > Amor > > __________________________________________________ > > > Schutz gegen Massenmails. > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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. > > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ 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.