You could subset
the dataset by selecting only those columns, and then do the lm
.
lm(Y~., data=df1[c(1,25:60)])
Suppose, if you need var25
to var60
and if the data is ordered by column names
lm(Y~., data=df1[c(1,26:61)])
Or another option would be to use paste
to create the formula
lm(paste("Y ~", paste(paste0('var', 25:60), collapse="+")), data=df1)
data
set.seed(24)
df1 <- as.data.frame(matrix(sample(1:80, 20*101, replace=TRUE),
ncol=101, dimnames=list(NULL, c('Y', paste0('var', 1:100)))))