I have a dataframe that has 1000 rows and 10 columns. First column is my y variable and rest of the columns are x variables. I would like to fit 10 different linear regression on 10 different subsets of data. For example: row1:100 first subset, row101:200 second subset etc...I would like to store output of each linear model (slope values) in a row of a new dataset. Is there an easy way to do this? I tried below:
for (i in 1:10 ) {
model_var[i] = lm(y[(100*(i-1)+1:100*i]~.,var)
# var is my dataframe that has all the data
#model_var[i] will store linear models
}
But I got an error. It seems that R doesn't allow to fit linear model to subset of a data.