[R] Generating a matrix

Srdjan Santic srdjan.santic at gmail.com
Tue Dec 3 12:43:39 CET 2013


I'm trying to write a function that will generate a NxN matrix that has 
the value K on both diagonals, while the values outside the diagonals 
(up and down) are 1's (for conflicting positions such as [4,5] and [5,4] 
the larger value is written in the matrix). Basically, I'm trying to 
replicate this matrix (where N = 8 and K = 5):

5  1  0  0  0  0  1  5
1  5  1  0  0  1  5  1
0  1  5  1  1  5  1  0
0  0  1  5  5  1  0  0
0  0  1  5  5  1  0  0
0  1  5  1  1  5  1  0
1  5  1  0  0  1  5  1
5  1  0  0  0  0  1  5

Any ideas? Thank you!

Srdjan Santic, M.Sc.
Graduate Student
Faclty of Economics
University of Belgrade
Serbia

---
This email is free from viruses and malware because avast! Antivirus protection is active.



More information about the R-help mailing list