Hi, I am trying to make a variable in a formula statement without success. I have ten undependent variables X1 through X10, and I am trying to use them one at a time in the formula statement. The error I get is

Error in model.frame.default(formula = formula, data = df, drop.unused.levels = TRUE) :

variable lengths differ (found for 'Z'). Please advise. Thank you.

t <- vector()

for (i in 1:10){

Z <- paste("X",i,sep="")

formula <- Y ~ Z

model <- lm(formula, data=df)

model_summary <- summary(model)

t[i] <- model_summary$coefficients[2,3] # test statistic for beta1

}

t