title: Replacing a string with a random number from vector
body: <p>I have a dataframe which includes grades of students per course. These grades, however, are in A-F format and need to be transformed to numerical grades (10-1). To do so, I generated random numbers that represent these A-F values. </p>
  
  <pre class="lang-r prettyprint-override"><code>A &lt;- rnorm(nrow(Student_Data), 9.45, 0.2)
  B &lt;- rnorm(nrow(Student_Data), 7.95, 0.2)
  C &lt;- rnorm(nrow(Student_Data), 6.25, 0.2)
  D &lt;- rnorm(nrow(Student_Data), 4.75, 0.2)
  F &lt;- rnorm(nrow(Student_Data), 2, 0.2)
  </code></pre>
  
  <p>I also created a function which allows to replace the letters with numbers</p>
  
  <pre class="lang-r prettyprint-override"><code>courseGradesNumeric &lt;- data.frame(lapply(courseGrades, function(x) {gsub("A", sample(A, 1), gsub("B", sample(B, 1), gsub("C", sample(C, 1), gsub("D", sample(D, 1), gsub("F", sample(F, 1), x)))))}))
  </code></pre>
  
  <p>This works quite well but the problem is that if there is an <code>"A"</code> (or any other letter) in a column, then this A in this specific column is replaced by a random number from <code>vector A</code> that is the same across the entire column. </p>
  
  <p>To illustrate:</p>
  
  <p>Current dataframe (ignore the NA's for now)</p>
  
  <pre class="lang-r prettyprint-override"><code>Student_ID       ABC1000_Grade   ABC1003_Grade 
  1    9000006           A              B          
  2    9000014           A              A          
  3    9000028           B              C          
  4    9000045          &lt;NA&gt;           &lt;NA&gt;          
  5    9000080           C             &lt;NA&gt;          
  6    9000091          &lt;NA&gt;           &lt;NA&gt; 
  </code></pre>
  
  <p>The problem:</p>
  
  <pre class="lang-r prettyprint-override"><code>Student_ID       ABC1000_Grade   ABC1003_Grade 
  1    9000006        9.335523      8.231295          
  2    9000014        9.335523      9.462468          
  3    9000028        7.972959      6.394259          
  4    9000045          &lt;NA&gt;           &lt;NA&gt;          
  5    9000080        6.257297         &lt;NA&gt;          
  6    9000091          &lt;NA&gt;           &lt;NA&gt; 
  </code></pre>
  
  <p>In the ABC1000_Grade column, the A was replaced by the same random number that was generated in an earlier step. </p>
  
  <p>How can I make sure that all replaced values are different random numbers? Thus, the preferred result should be:</p>
  
  <pre class="lang-r prettyprint-override"><code>Student_ID       ABC1000_Grade   ABC1003_Grade 
  1    9000006        9.510445      8.231295          
  2    9000014        9.335523      9.462468          
  3    9000028        7.972959      6.394259          
  4    9000045          &lt;NA&gt;           &lt;NA&gt;          
  5    9000080        6.257297         &lt;NA&gt;          
  6    9000091          &lt;NA&gt;           &lt;NA&gt; 
  </code></pre>