title: Can I extract a variable name from a vector using a for loop?
body: <p>I am practicing loops and trying to figure out how to print <code>___ is a good friend</code> if their number is odd (through an assigned number in a vector) - why won't it print the names of the people in the vector who are coded as odd numbers?</p>
  <pre class="lang-r prettyprint-override"><code>B_list &lt;- c(Bob=1, Bill=2, Buddy=3) # create character vector
  
  phrase &lt;- &quot;is a good friend&quot;
  
  for (i in B_list){
      if((i %% 2) != 0)
          print(paste(names(i),phrase))
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>[1] &quot; is a good friend&quot;
  [1] &quot; is a good friend&quot;
  </code></pre>