R 3 天大,无法弄清楚我做错了什么。我正在尝试将一些具有两种交互方式的列发送到 glmnet cox 模型中。我有一些名为 dtable 的 data.frame()
编辑以使代码可重现
xs<-c("Col1", "Col2", "Col3")
v<-c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, NA, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, NA, 25, 26, 27, 28, 29, 30)
df<-data.frame(matrix(v,ncol=3))
dm<-as.matrix(df)
dm<-matrix(dm[complete.cases(dm)], ncol=3)
colnames(dm)<-xs
dfdata<-data.frame(dm)
f<-as.formula(time~.*.)
xmatrix<-model.matrix(f, dfdata)[,-1]
当我运行它时,我得到了错误
Error in model.frame.default(object, data, xlev = xlev) :
object is not a matrix
提前致谢