title: Coding data and changing the column names in another columns using codes in R and tidyverse
body: <p>below, I have demonstrated part of my  data:</p>
  
  <pre><code>df&lt;-read.table(text=" K G   M
  12  2345    Gholi
  KAM 2345    KAM
  Noghl   1990    KAM
  Zae 1990    441
  12  2345    441
  KAM 1990    12
  Noghl   1800    12"
  
  ,header=TRUE)
  </code></pre>
  
  <p>I would like to make codes for  K, G and M and starting with 1. We have 4 groups in K, so 1,2,3 and 4. for G, start with 5, so 5, 6 and 7 as we have three subgroups.</p>
  
  <p>Using the following codes, I will get the following table:</p>
  
  <pre><code>df = lapply(df, function(x) as.integer(as.factor(x)))
  data.frame(Map("+", df, cumsum(c(0, head(sapply(df, max), -1)))))
  </code></pre>
  
  <p>I will get the following table:</p>
  
  <pre><code>KM  KN  KZ
  1   7   10
  2   7   11
  3   6   11
  4   6   9
  1   7   9
  2   6   8
  3   5   8
  </code></pre>
  
  <p>Now I want to get the following table:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Group C
  K,M 1,8
  K,M 2,11
  K 3
  K 4
  G 7
  G 6
  M 10
  M 9</code></pre>
  </div>
  </div>
  </p>
  
  <p>For example, in Group, Column K (12), M (12,12) goes to Codes 1 and 8, as they coded in KM and KZ and so</p>