0
#data splicing
set.seed(12345)
train <- sample(1:nrow(student.mat.pass.or.fail),size = 
ceiling(0.80*nrow(student.mat.pass.or.fail)),replace = FALSE)

# training set
students_train <- student.mat.pass.or.fail[train,]
# test set
students_test <- student.mat.pass.or.fail[-train,]

# penalty matrix
penalty.matrix <- matrix(c(0,1,10,0), byrow=TRUE, nrow=2)

# building the classification tree with part
tree <- rpart(class~.,
          data =  students_train, # as.matrix(students_train)
          parms = list(loss = penalty.matrix),
          method = "class")        

object is not a matrix, can someone help me cause I'm new in R I also used the as. matrix(students_train) but it still showing the same problem

Phil
  • 7,287
  • 3
  • 36
  • 66
  • 1
    It's easier to help you if you provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jun 09 '22 at 14:38
  • 1
    Are you sure your ```student.mat.pass.or.fail``` only contains one kind of datatype? For example numeric or character, otherwise your ```students_train``` can never be a matrix. – Omniswitcher Jun 09 '22 at 14:46

0 Answers0