title: Preserve names when coercing vector from binary to `as.numeric`?
body: <p>In R, when you coerce a vector from binary to numeric, the names are stripped away.</p>
  
  <p>There are a few possible solutions, which I've outlined before. It seems dangerous to rely on implicit conversion by adding 0 to all the values, and the <code>sapply()</code> adds an additional loop to my operations (which seems inefficient). Is there any other way to preserve the names when converting a vector using <code>as.numeric</code>?</p>
  
  <pre><code># Set the seed
  set.seed(1045)
  
  # Create a small sample vector and give it names
  example_vec &lt;- sample(x = c(TRUE,FALSE),size = 10,replace = TRUE)
  names(example_vec) &lt;- sample(x = LETTERS,size = 10,replace = FALSE)
  
  example_vec
  #     Y     N     M     P     L     J     H     O     F     D 
  # FALSE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE 
  
  as.numeric(x = example_vec)
  #  [1] 0 1 0 0 1 1 1 1 1 1
  
  example_vec + 0
  # Y N M P L J H O F D 
  # 0 1 0 0 1 1 1 1 1 1 
  
  sapply(X = example_vec,FUN = as.numeric)
  # Y N M P L J H O F D 
  # 0 1 0 0 1 1 1 1 1 1
  </code></pre>