title: replace a list of values by another in R
body: <p>I have a dataframe with any of these values.</p>
  
  <pre><code>from=c("A","C","G","T","R","Y","M","K","W", "S","N")
  </code></pre>
  
  <p>and I want to replace accordingly with</p>
  
  <pre><code>to=c("AA","CC","GG","TT","AG","CT","AC","GT","AT", "CG","NN")
  </code></pre>
  
  <p>What is the best way to do that , loop over all values to replace? or loop over matrix position. or any other solution?</p>
  
  <pre><code>dd&lt;-matrix(sample(from, 100, replace=TRUE), 10) 
  
  dd
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
   [1,] "K"  "S"  "G"  "T"  "R"  "N"  "A"  "C"  "W"  "M"  
   [2,] "Y"  "K"  "S"  "G"  "T"  "R"  "N"  "A"  "C"  "W"  
   [3,] "M"  "Y"  "K"  "S"  "G"  "T"  "R"  "N"  "A"  "C"  
   [4,] "W"  "M"  "Y"  "K"  "S"  "G"  "T"  "R"  "N"  "A"  
   [5,] "C"  "W"  "M"  "Y"  "K"  "S"  "G"  "T"  "R"  "N"  
   [6,] "A"  "C"  "W"  "M"  "Y"  "K"  "S"  "G"  "T"  "R"  
   [7,] "N"  "A"  "C"  "W"  "M"  "Y"  "K"  "S"  "G"  "T"  
   [8,] "R"  "N"  "A"  "C"  "W"  "M"  "Y"  "K"  "S"  "G"  
   [9,] "T"  "R"  "N"  "A"  "C"  "W"  "M"  "Y"  "K"  "S"  
  [10,] "G"  "T"  "R"  "N"  "A"  "C"  "W"  "M"  "Y"  "K"
  </code></pre>
  
  <p>I used loop over all from to to. </p>
  
  <pre><code>myfunc&lt;-function(xx){
  
    from=c("A","C","G","T","R","Y","M","K","W", "S","N");
    to=c("AA","CC","GG","TT","AG","CT","AC","GT","AT", "CG","NN");
    for (i in 1:11){
        xx[xx==from[i]]&lt;-to[i];
    }
    return(xx);
  }
  </code></pre>
  
  <p>it worked great for small matrix, but takes a long time for big matrix. Any effcient solution?</p>
  
  <p>Thanks</p>