Here is my code
library(ISLR)
attach(Weekly)
train = (Weekly$Year < 2009)
Weekly.0910 = Weekly[!train, ]
glm.fit3 = glm(Direction ~ Lag2, data = Weekly, family = binomial, subset = train)
glm.fit4 = glm(Weekly$Direction ~ Weekly$Lag2, data = Weekly, family = binomial, subset = train)
glm.probs3 = predict.glm(glm.fit3, Weekly.0910, type = "response")
glm.pred3 = rep("Down" length(glm.probs3))
glm.pred3[glm.probs3 > 0.5] = "Up"
Direction.0910 = Direction[!train]
conf_mat2 = table(glm.pred3, Direction.0910)
the code above works as expected, but if I use glm.fit4 instead (even though its should be identical to glm.fit3), replacing the references to glm.fit3 with glm.fit4 then I get this error
Error in table(glm.pred4, Direction.0910) :
all arguments must have the same length
In addition: Warning message:
'newdata' had 104 rows but variables found have 1089 rows