'Why am I getting different statistical outputs than my partner using the same code?

I'm trying to fit a classification tree to the OJ dataset using the ISLR2 textbook. The response variable is "Purchase" which takes one of two values: "MM" or "CH".

library(ISLR2)
library(tree)
# (a) Create a training set containing a random sample of 800 obs
# and a test set containing the remaining observations. 
set.seed(1)
train <- sample(1:nrow(OJ), 800)
# (b) Fit a regression tree to the training set. Plot the tree, and 
# calculate the test MSE.
OJ.test <- OJ[-train, ]
tree.oj <- tree(Purchase~., OJ, subset = train) ##Produces error "NAs introduced by coercion"
plot(tree.oj) ##Produces error "Cannot plot singlenode tree"

My question is, does something seem wrong with my code or could I have an issue with R studios on my computer? I have the same code as my class partner and she can run the code fine. We also had the same code for our last assignment, but when I ran the code I produced different statistics in repeated runs. This has happened a few other times and it leads me to believe there's an issue with my computer and R, rather than the code. Any suggestions on where to start to resolve this?

r


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source