title: Mapping Data in R with missing values
body: <p>I'm very new with R, and I'm trying to map data dictionary definitions to a set of data to make more readable text.</p>
  
  <p>For example, based on the data dictionary within the Ames Iowa housing dataset currently on Kaggle, I'm trying to map the zoning of houses.</p>
  
  <pre><code>mapping &lt;- list(
    'A'='Agriculture',
    'C (all)'='Commercial',
    'FV'='Floating Village Residential',
    'I'='Industrial',
    'RH'='Residential High Density',
    'RL'='Residential Low Density',
    'RP'='Residential Low Density Park',
    'RM'='Residential Medium Density'
  )
  
  housingData$MSZoning &lt;- as.factor(as.character(mapping[origData$MSZoning]))
  </code></pre>
  
  <p>The original data set does not contain values for all of these data points, however.</p>
  
  <pre><code>&gt; table(origData$MSZoning)
  
  C (all)      FV      RH      RL      RM 
       10      65      16    1151     218 
  </code></pre>
  
  <p>After mapping with my code, the key value pairs don't align. (Agriculture is mapped to "C", for example.) I believe that the empty values in the source data are throwing off my mapping.</p>
  
  <pre><code>&gt; table(housingData$MSZoning, origData$MSZoning)
  
                                 C (all)   FV   RH   RL   RM
    Agriculture                       10    0    0    0    0
    Commercial                         0   65    0    0    0
    Floating Village Residential       0    0   16    0    0
    Industrial                         0    0    0 1151    0
    Residential High Density           0    0    0    0  218
  </code></pre>
  
  <p>What is a more appropriate way to ensure that these keys and values align appropriately?</p>