title: Importing Correlation Matrix
body: <p>I have a ready-made correlation matrix to visualize in <code>R</code> with <code>corrplot</code> (or other relevant) package. I do not have raw data to produce correlations with <code>cor()</code> function. </p>
  
  <p>The problem is just to import the matrix from a .csv file and to perform some actions (visualisation, dendritic graph and so on) with it. However, <code>R</code> does not recognize the matrix as such where <code>corrplot</code> can be applied. I used </p>
  
  <pre><code>M&lt;-read.csv("myfile.csv") 
  </code></pre>
  
  <p>then</p>
  
  <pre><code>Mcor &lt;- as.matrix(M) 
  </code></pre>
  
  <p>Next, I added identical names of rows and columns:</p>
  
  <pre><code>rownames(Mcor)&lt;-my_cols_names
  colnames(Mcor)&lt;-my_cols_names
  </code></pre>
  
  <p>It shows the structure, identical to the "true" correlation matrix, produced from raw data with <code>cor()</code>:</p>
  
  <pre><code>&gt; str(Mcor)
   num [1:25, 1:25] 1 0.58 -0.43 -0.39 0.06 0.1 -0.3 -0.2 -0.06 -0.3 ...
   - attr(*, "dimnames")=List of 2
   ..$ : chr [1:25] "V1" "V2" "V3" "V4" ...
   ..$ : chr [1:25] "V1" "V2" "V3" "V4" ...
  </code></pre>
  
  <p>However, <code>corrplot(Mcor)</code> gives</p>
  
  <blockquote>
    <p>Error in corrplot(Mcor) : The matrix is not in [-1, 1]!</p>
  </blockquote>
  
  <p>The problem appeared trivial and caused by a typo mistake in entering data: one number appeared to be >1.</p>
  
  <p>The way to check this, as suggested in comments: 
  1)run the command</p>
  
  <p>any(abs(Mcor)>1)</p>
  
  <p>it gives TRUE, if there are wrong numbers in data (absolute values >1)</p>
  
  <p>2) subsequently try to draw correlation plots for smaller sets:</p>
  
  <p>corrplot(Mcor[1:5,1:5])</p>
  
  <p>then</p>
  
  <p>corrplot(Mcor[1:10,1:10])</p>
  
  <p>until the error (wrong column) is localized (failure to build a plot with (n+1)x(n+1) matrix, if nxn is OK). Or directly reveal the wrong number(s), for example, with <em>which</em> command </p>