title: Replacing columns names using a data frame in r
body: <p>I have the matrix</p>
  
  <pre><code>m &lt;- matrix(1:9, nrow = 3, ncol = 3, byrow = TRUE,dimnames = list(c("s1", "s2", "s3"),c("tom", "dick","bob")))
  
     tom dick bob
  s1   1    2   3
  s2   4    5   6
  s3   7    8   9
  
  #and the data frame
  
  current&lt;-c("tom", "dick","harry","bob")
  replacement&lt;-c("x","y","z","b")
  df&lt;-data.frame(current,replacement)
  
    current replacement
  1     tom           x
  2    dick           y
  3   harry           z
  4     bob           b
  
  #I need to replace the existing names i.e. df$current with df$replacement if 
  #colnames(m) are equal to df$current thereby producing the following matrix
  
  
  m &lt;- matrix(1:9, nrow = 3, ncol = 3, byrow = TRUE,dimnames = list(c("s1", "s2", "s3"),c("x", "y","b")))
  
     x y b
  s1 1 2 3
  s2 4 5 6
  s3 7 8 9
  </code></pre>
  
  <p>Any advice? Should I use an 'if' loop? Thanks.</p>