title: r creation diagonal matrix from vector with use upper.tri function
body: <p>I have vector </p>
  
  <pre><code>vector= c(4,6,2,9)
  </code></pre>
  
  <p>I need to get diagonal matrix looking like this (second column should contatain vector scrolled down on one element, third - on two elements etc.): </p>
  
  <pre><code>4 0 0 0
  6 4 0 0
  2 6 4 0
  9 2 6 4
  </code></pre>
  
  <p>As I could undestand I should use upper.tri.</p>
  
  <p>I tried this one :</p>
  
  <pre><code>vector = c(4,6,2,9)
  vector_length=length(a)
  MATRIX= matrix(0, vector_length, vector_length)
  MATRIX[!upper.tri(MATRIX)]=vector 
  MATRIX
  </code></pre>
  
  <p>and failed because the  result was</p>
  
  <pre><code>       [,1] [,2] [,3] [,4]
  [1,]    4    0    0    0
  [2,]    6    4    0    0
  [3,]    2    6    9    0
  [4,]    9    2    4    6
  </code></pre>
  
  <p>How should I use this function correctly? And How should I solve my problem?</p>