Created
January 26, 2012 18:50
-
-
Save tpoisot/1684333 to your computer and use it in GitHub Desktop.
Permutation of a matrix with the diagonal kept constant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mat = matrix(abs(round(rnorm(100,15,8),0))+1,10) | |
diag(mat) = 0 | |
print(mat) | |
permat = function(mat) | |
{ | |
mat[lower.tri(mat)+upper.tri(mat)==1] = sample(mat[lower.tri(mat)+upper.tri(mat)==1],replace=FALSE) | |
return(mat) | |
} | |
replicate(100,permat(mat)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment