title: CSV Matrix in R
body: <p>I am a beginner in R. I have a row standardized matrix (1542x1542) that I created in excel and saved as a .csv file. I am trying to use the matrix in R to calculate Moran's I. -using the following command:</p>
  <pre><code># Weights Matrix Based on Connectivity
  sw &lt;- read.csv(file = &quot;20210929_Weights_Matrix.csv&quot;)
  sw.2.mat &lt;- as.matrix(sw)
  
  ## mat to listw
  mat2listw(sw.2.mat)
  dnn.2.listw = nb2listw(sw.2.mat, zero.policy=T)
  </code></pre>
  <p>However, when I run the command I get the following errors</p>
  <pre><code>sw &lt;- read.csv(file = &quot;20210929_Weights_Matrix.csv&quot;)
  sw.2.mat &lt;- as.matrix(sw)
  mat2listw(sw.2.mat) Error in mat2listw(sw.2.mat) : x must be a square matrix
  
  dnn.2.listw = nb2listw(sw.2.mat, zero.policy=T) 
  Error in nb2listw(sw.2.mat, zero.policy = T) : Not a neighbours list
  </code></pre>
  <p>When I try to add an additional row in excel, I get the following error in R</p>
  <pre><code>sw &lt;- read.csv(file = &quot;20210929_Weights_Matrix.csv&quot;)
  sw.2.mat &lt;- as.matrix(sw)
  ## mat to listw
  mat2listw(sw.2.mat)
  
  Error in if (any(x &lt; 0)) stop(&quot;values in x cannot be negative&quot;) : 
        missing value where TRUE/FALSE needed
  
  dnn.2.listw = nb2listw(sw.2.mat, zero.policy=T)
  
  Error in nb2listw(sw.2.mat, zero.policy = T) : Not a neighbours list
  </code></pre>
  <p>Could someone please help? Is there a possibility I can share my excel?</p>