title: How to segment data into two sets using dplyr's setdiff
body: <p>I'm using dplyr to do a simple split of some data into training and test.</p>
  
  <p>When I do a simple example, it works great:</p>
  
  <pre><code>a = c(1, 2, 3, 4, 5, 6, 7, 8)
  b = c("A", "B", "C", "D", "E", "F", "G", "H")
  
  df = data.frame(a, b)
  
  train = sample_frac(df, 0.8)
  test = setdiff(df, train)
  
  &gt; nrow(train) + nrow(test) == nrow(df)
  [1] TRUE
  </code></pre>
  
  <p>However when I try to do the same thing using the classic UCI Wine dataset, I don't seem to get the same results:</p>
  
  <pre><code>wine = read.csv("http://www.nd.edu/~mclark19/learn/data/goodwine.csv")
  
  wine_train = sample_frac(wine, 0.8)
  wine_test = setdiff(wine, wine_train)
  
  &gt; nrow(wine_train) + nrow(wine_test) == nrow(wine)
  [1] FALSE
  &gt; nrow(wine_train) + nrow(wine_test)
  [1] 6105
  &gt; nrow(wine)
  [1] 6497
  </code></pre>
  
  <p>Is there something about the behavior of setdiff that I'm missing?</p>
  
  <p>Thanks,
  AG</p>