Error while using predict
Works find for me. Maybe you have some error in the definition of the train/test set? 

library(ISLR)
library(glmnet)
# Load data
iris = iris[iris$Species=="Setosa" | iris$Species=="versicolor",]
iris$Species = as.factor(iris$Species)
# Make a test/train split
set.seed(123)
smp_size &lt;- floor(0.75 * nrow(iris))
train_ind &lt;- sample(seq_len(nrow(iris)), size = smp_size)
train &lt;- iris[train_ind, ]
test &lt;- iris[-train_ind, ]

m1 = glm(Species ~ ., data = train, family="binomial")
p = predict(m1,newdata=test, type="response")
table(test$Species, p&gt;0.5)