Skip to content
Prev 305000 / 398506 Next

creating a symmetric matrix

You asked for existing functions, but I was more intrigued by trying to
create one:

symmat <- function(n) {
     x <- matrix(1:n, nrow=n, ncol=n)
     abs(x-col(x))+1
}
[,1] [,2] [,3] [,4]
[1,]    1    2    3    4
[2,]    2    1    2    3
[3,]    3    2    1    2
[4,]    4    3    2    1

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352