title: Using R, Randomly Assigning Students Into Groups Of 4
body: <p>I'm still learning R and have been given the task of grouping a long list of students into groups of four based on another variable. I have loaded the data into R as a data frame. How do I sample entire rows without replacement, one from each of 4 levels of a variable and have R output the data into a spreadsheet?</p>
  
  <p>So far I have been tinkering with a for loop and the sample function but I'm quickly getting over my head. Any suggestions? Here is sample of what I'm attempting to do. Given:</p>
  
  <pre><code>Last.Name &lt;- c("Picard","Troi","Riker","La Forge", "Yar", "Crusher", "Crusher", "Data")
  First.Name &lt;- c("Jean-Luc", "Deanna", "William", "Geordi", "Tasha", "Beverly", "Wesley", "Data")
  Email &lt;- c("a@a.com","b@b.com", "c@c.com", "d@d.com", "e@e.com", "f@f.com", "g@g.com", "h@h.com")
  Section &lt;- c(1,1,2,2,3,3,4,4)
  
  df &lt;- data.frame(Last.Name,First.Name,Email,Section)
  </code></pre>
  
  <p>I want to randomly select a Star Trek character from each section and end up with 2 groups of 4. I would want the entire row's worth of information to make it over to a new data frame containing all groups with their corresponding group number.  </p>