title: in R, how to set and retain custom levels in factor with different labels?
body: <p>in R, how to set and retain custom levels in factor with different labels ?</p>
  
  <p>That is, I want to set custom numbers in the levels of a factor, and these numerical values - integers to be retained and not converted to "1, 2, 3 etc.". </p>
  
  <p>I know that one solution is to set these weights as Labels, but then I will missing the "labels" of the factor.</p>
  
  <p>The "weighted" distance between factors is not retained. Is it possible in R, to achieve something like this, using a single variable ?  </p>
  
  <p>For example: </p>
  
  <pre><code>age_f &lt;- factor( c(1, 10, 100), levels = c( 1, 10, 100 ), labels = c( "baby", "child", "old" ), ordered = T )
  </code></pre>
  
  <blockquote>
  <pre><code>levels(age_f)
     [1] "baby"  "child" "old"  
  labels(age_f)
     [1] "1" "2" "3"
   labels(levels(age_f))
      [1] "1" "2" "3"
   as.numeric(age_f)
      [1] 1 2 3
  
  Desired output: 
   as.numeric(age_f)
          [1] 1 10 100
  </code></pre>
  </blockquote>
  
  <p>If this does not exists in R factors, it is easy to produce such result by a custom function? </p>