我想在 Rglm
中为数据集执行Titanic
。我执行了以下步骤来准备数据并运行 glm:
install.packages("reshape")
library(reshape)
data=(Titanic)
da=melt(Titanic)
m=dim(da)[1]
for (i in 1:m){
if (da[i,5]!=0){
for (k in 1:da[i,5]){
da=rbind(da,da[i,])
}
}
}
one=rep(1, dim(da)[1])
x=as.matrix(cbind(one,da[,1:3]))
y=da[,4]
m1=glm(y~x,family=binomial)
我收到错误消息:
Error in `[[<-.data.frame`(`*tmp*`, i, value = c(1L, 1L, 1L, 1L, 1L, 1L, :
replacement has 8932 rows, data has 2233
谁能帮我解决这个问题?