title: Attach Labels to numeric codes of a data frame in R - efficient use of factors
body: <p>I have a data which is in excel and I read that to store it in a data frame by the name "data". Similarly I the value labels for each variable and its code in a separate sheet by the name map. I read this sheet as well and store it is data frame by the name "map". </p>
  
  <p>Link to the file is - <a href="https://www.wetransfer.com/downloads/bf0c5bfa88be20e4037d7fdc828ca66320161018075428/7f82a4" rel="nofollow">https://www.wetransfer.com/downloads/bf0c5bfa88be20e4037d7fdc828ca66320161018075428/7f82a4</a></p>
  
  <p>Below is the code to read the sheets- </p>
  
  <pre><code>library("readxl")
  data &lt;- read_excel("data_v1.xlsx",sheet = "data")
  map &lt;- read_excel("data_v1.xlsx",sheet = "map")
  </code></pre>
  
  <p>If you will notice the cells with less number of codes are with NA.</p>
  
  <p>Now I want to attach the value labels to each of the codes from the map sheet to the data. I was doing a search and I realized that one of the ways to do this is by using factors. Where we define the levels and labels. I can use the original variable name in map file for the levels and for Labels I can use those with "_desc" as suffix.</p>
  
  <p>Can some one please suggest an efficient way of doing this? I mean instead of writing codes for individual variables if we can do this in a loop? In the data file that i am attaching this is just a sample and the original data file would have more than 100 variables for which one would need to do this task of attaching labels.</p>
  
  <p>Lastly, how can I attach variable labels? I mean, </p>
  
  <p>Q1 should have the label "Like the packaging of the brand"
  Q2 should have the label "Like the taste of the brand"
  Q3 should have the label "Like the smell of the brand"
  Q4 should have the label "value for money"</p>
  
  <p>Should I think of creating a separate sheet with one column having the variable name and next one having the labels for the variables? How would we attach these labels to the variables as factors only works for values I believe.</p>
  
  <p>Finally I need to generate Table / cross tables where these Labels should get displayed. Charts where these value + Variable labels should get displayed.</p>
  
  <p>Thank you!!</p>
  
  <p>Prasad</p>