多変量の回帰式を作る

help(formula)
## Create a formula for a model with a large number of variables:
xnam <- paste("x", 1:25, sep="")
(fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+"))))
k<-4 # 例えば
xnam <- paste("Fs[,", 1:k, "]",sep="")
(fmla <- as.formula(paste("Vs ~ ", paste(xnam, collapse= "+"))))
  • 結果
>k<-4 # 例えば
>xnam <- paste("Fs[,", 1:k, "]",sep="")
> (fmla <- as.formula(paste("Vs ~ ", paste(xnam, collapse= "+"))))
Vs ~ Fs[, 1] + Fs[, 2] + Fs[, 3] + Fs[, 4]