2
在下面的重複代碼(最後一行)中,如果用'fieldToRemove'替換'收入','更新'功能不起作用。我如何使這個功能起作用?我需要在循環中運行該行。如何'更新'使用'glm'構建的模型R
state.x77
tmpData = as.data.frame(state.x77)
colnames(tmpData)[4] = "Life.Exp"
colnames(tmpData)[6] = "HS.Grad"
cnames = colnames(tmpData)
cnames
lenCnames = length(cnames)
rhsOfFormula = paste(cnames[1:(length(cnames)-1)],collapse= "+")
lhsOfFormula = cnames[length(cnames)]
(fmla <- as.formula(paste(lhsOfFormula , " ~ ", rhsOfFormula)))
modelTmp <- glm(formula = fmla, data=tmpData)
fieldToRemove = 'Income'
newModel <- update(modelTmp, .~.-Income)
感謝,擔任所需 – user1140126 2013-02-11 20:15:56