Error in xj[i, , drop = FALSE] : (subscript) logical subscript too long - When running predicition with rpart

Hi All,

Seeking for help.
When i am trying to run this script, an error occur when running this statement. PredictedTerminatedEmployees2016<-subset(ActiveEmployees2016,PredictedSTATUS2016=='TERMINATED')
How can i rectify this statement and error to make it works?

#Apply model

#Generate 2016 data
Employees2016<-MYtest #2015 data

ActiveEmployees2016<-subset(Employees2016,STATUS=='ACTIVE')
ActiveEmployees2016$age<-ActiveEmployees2016$age+1
ActiveEmployees2016$length_of_service<-ActiveEmployees2016$length_of_service+1
ActiveEmployees2016$PredictedSTATUS2016<-predict(MYrpart,ActiveEmployees2016)
PredictedTerminatedEmployees2016<-subset(ActiveEmployees2016,PredictedSTATUS2016=='TERMINATED')
Error in xj[i, , drop = FALSE] : (subscript) logical subscript too long

The data structure is

Capture|690x271

Regards,
Ernest

Would you be able to make this into a minimal reproducible example (aka a reprex)?

In addition to the reprex section of the tidyverse site (linked to above), there's a quick, helpful overview of the package and how to use it in this video. (The most relevant material starts ~10:40).

You can also see the slides from that video here: