title: Create Training and Test Dataset in R
body: <p>I want to create training and test data from <code>mydata</code>, which has 2673 observations and 23 variables. However, I am not able to create the test set just by simply subtracting the training data. </p>
  
  <pre><code>dim(mydata)
  ## [1] 2673   23
  set.seed(1)
  train = mydata[sample(1:nrow(mydata), 1000, replace=FALSE), ]
  dim(train)
  ## [1] 1000   23
  </code></pre>
  
  <p>When I run the following, I got 19 warnings and the the result has 20,062 observations:</p>
  
  <pre><code>test = mydata[!train, ]
  ## There were 19 warnings (use warnings() to see them)
  dim(test)
  ## [1] 20062    23
  </code></pre>
  
  <p>What am I doing wrong?</p>