連続する2つの値をシャッフル
入力例
c(1,2,3,4,5)
出力例
> local_shuffle(c(1,2,3,4,5))
[1] 1 2 4 3 5
> local_shuffle(c(1,2,3,4,5))
[1] 1 2 3 4 5
> local_shuffle(c(1,2,3,4,5))
[1] 2 1 3 4 5
> local_shuffle(c(1,2,3,4,5))
[1] 2 1 4 3 5
> local_shuffle(c(1,2,3,4,5))
[1] 1 2 3 4 5
local_shuffle<-function(cc){ if(length(cc)%%2==1){ ccc<-cc[1:(length(cc)-1)] l<-c(as.vector(apply(matrix(ccc,2),2,sample)),cc[length(cc)]) }else{ l<-as.vector(apply(matrix(cc,2),2,sample)) } l }
連続するk個の値
local_shuffle3<-function(cc,k){ if(length(cc)%%k != 0){ index<-(length(cc)%/%k)*k ccc<-cc[1:(index)] l<-c(as.vector(apply(matrix(ccc,k),2,sample)),cc[(index+1):length(cc)]) }else{ l<-as.vector(apply(matrix(cc,k),2,sample)) } l }