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