To illustrate I use the segmentationOriginal
dataset from the AppliedPredictiveModeling
package:
> library(AppliedPredictiveModeling)
> data(segmentationOriginal)
> levels(factor(segmentationOriginal$Case))
[1] "Test" "Train"
The authors of the data set have the training and testing data intermixed in the data set, so I wanted to separate the two types of data into separate data frames:
> training <- segmentationOriginal[segmentationOriginal$Case=="Train", ]
> testing <- segmentationOriginal[segmentationOriginal$Case=="Test", ]
However, the Case
variable of the training
data set still has two factor levels:
> str(training$Case)
Factor w/ 2 levels "Test","Train": 2 2 2 2 2 2 2 2 2 2 ...
even if there is not a single Test
factor in the Case
variable any longer of the training set:
> which(training$Case == "Test")
integer(0)
Why is that or what is going on?