我有一个向量:
X <-c("A","B","C","D") # and Y is "Y"
Z <-c("R","T","G","U","I")
XY <- matrix(1:150, ncol = 10)
colnames(XY)<- c("Y", X, Z)
目标是:
for (i in 1: length(X)){
for (j in 1:length(X)){
lm(Y~X[i]+X[j], data=XY)
}
}
问题是: X[1] = "A" 和 lm(Y~"A", data=XY) 不会读取。
cat(X) 和因子 (X) 不起作用。cat(X[1]) 或 factor(X[1]) 都不是。