> 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. Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} ______________________________________________ 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.