R/perms.R

perms <-
function(n){

if (n==1){
     	return(matrix(1))
	} else{
	if (n<2){
		stop("n must be a positive integer")
	}
}
z=matrix(1) 
for (i in 2:n){
	x=cbind(z,i)
    a=c(1:i,1:(i-1))
    z=matrix(0,ncol=ncol(x),nrow=i*nrow(x))
    z[1:nrow(x),]=x 
    for (j in 2:i-1){
	    z[j*nrow(x)+1:nrow(x),]=x[,a[1:i + j]]
    }
}
dimnames(z)=NULL 
return(z)
}

Try the ThreeWay package in your browser

Any scripts or data that you put into this service are public.

ThreeWay documentation built on May 2, 2019, 9:20 a.m.