title: How to recode multiple columns in R
body: <p>I tried my best to recode multiple columns, but I still struggle to do it. Here what I have done:</p>
  
  <pre><code>df&lt;-read.table(text="ZR1 Time1 ZR2 Time2 ZR3 Time3
    A 60  A   56  B   44
    C 61  B   44  D   78
    D 62  C   78  E   66
    E 58  D   46  B   45
    A 54  B   23  B   23
    A 57  E   24  B   100",h=T)
  </code></pre>
  
  <p>What I have done</p>
  
  <pre><code>for (i in 1) {
   ZRi&lt;-paste0("ZR", i)
  Zi&lt;-paste0("Z",i)}
  df[,Zi]=c(A=4,B=3,C=2,D=1,E=0)
   df[,Zi]=c(A=4,B=3,C=2,D=1,E=0)[df[,ZRi]]
  </code></pre>
  
  <p>I got this:</p>
  
  <pre><code>ZR1 Time1 ZR2 Time2 ZR3 Time3 Z1
  1   A    60   A    56   B    44  4
  2   C    61   B    44   D    78  3
  3   D    62   C    78   E    66  2
  4   E    58   D    46   B    45  1
  5   A    54   B    23   B    23  4
  6   A    57   E    24   B   100  4
  </code></pre>
  
  <p>As you can see, I could get Z1, which is wrong.</p>
  
  <p>I want to get this:</p>
  
  <pre><code>ZR1 Time1   ZR2 Time2   ZR3 Time3   Z1  Z2  Z3
  A   60  A   56  B   44  4   4   3
  C   61  B   44  D   78  2   3   1
  D   62  C   78  E   66  1   2   0
  E   58  D   46  B   45  0   1   3
  A   54  B   23  B   23  4   3   3
  A   57  E   24  B   100 4   0   3
  </code></pre>