title: If element used pick next from vector in R
body: <p>I'm quite new to R and unfortunately I can't find an answer to the problem below.</p>
  
  <p>I have a dataset:</p>
  
  <pre class="lang-r prettyprint-override"><code>df &lt;- data.frame(room = rep("room1.", 6),
                   name = c("piet", "klaas", "Sara", "mo.", "piet", "jo"),
                   time = c("9:00", "9:00", "12:00", "14:00", "14:00", "14:00"))
  df
  #&gt;     room  name  time
  #&gt; 1 room1.  piet  9:00
  #&gt; 2 room1. klaas  9:00
  #&gt; 3 room1.  Sara 12:00
  #&gt; 4 room1.   mo. 14:00
  #&gt; 5 room1.  piet 14:00
  #&gt; 6 room1.    jo 14:00
  </code></pre>
  
  <p>and a vector:</p>
  
  <pre><code>pcs &lt;- c("pc1", "pc2", "pc3")
  </code></pre>
  
  <p>I want to add a column <code>pc</code> where, based on an if statement, an element of the vector is added. If <code>pc</code> is empty, add the first element from the vector to column <code>pc</code>, but if the value in <code>time</code> already has been used pick the next element.</p>
  
  <p>desired output:</p>
  
  <pre><code>room   name  time  pc
  room1. piet  9:00  pc1
  room1. klaas 9:00  pc2
  room1. Sara  12:00 pc1
  room1. mo.   14:00 pc1
  room1. piet  14:00 pc2
  room1. jo    14:00 pc3
  </code></pre>