title: Replace matrix elements based on column and row names
body: <p>I have a matrix of elements with numeric values, e.g.:</p>
  
  <pre><code>&gt; mtx &lt;- as.matrix(read.csv("matrix.csv", header = TRUE, row.names = 1,sep = ","))
  &gt; head(mtx)
  
       BE   BG   EE   ES   FI
  BE 0.00 0.75 0.17 0.28 0.48
  BG 0.75 0.00 0.92 1.03 1.24
  EE 0.17 0.92 0.00 0.11 0.31
  ES 0.28 1.03 0.11 0.00 0.20
  </code></pre>
  
  <p>I want to replace values in certain elements with zero based on names of columns and rows. Namely, I want to have zero when column "BE" intersects with row "ES" and vice versa, i.e. when column "ES" intersects with row "BE", so I want to get:</p>
  
  <pre><code>     BE   BG   EE   ES   FI 
  BE 0.00 0.75 0.17 0.00 0.00 
  BG 0.75 0.00 0.92 1.03 1.24 
  EE 0.17 0.92 0.00 0.11 0.31 
  ES 0.00 1.03 0.11 0.00 0.00
  </code></pre>
  
  <p>I have to perform this operation for many matrices, which are larger than this example, so there are >150 pairs for which replacement is needed. Here's <a href="https://docs.google.com/document/d/1ag9E61lV4zhAe8pCwiHAGcwXbsDa9Gg1i-6j1JVV8GI/edit?usp=sharing" rel="nofollow noreferrer">data structure</a>. Replacement needed for: 
  <code>c('BE', 'FI', 'FR', 'DE', 'IE', 'NL', 'NO', 'SE', 'CH', 'GB', 'DK','PT','ES')</code></p>
  
  <p>I have found function <code>replace</code>, but it works apparently only based on criteria applied to the values, not to the names of rows and columns of elements that contain them...</p>