Looping regression and obtaining summary statistics in matrix form
问题 I am trying to do a similar regression for 25 different portfolios and then finding the R^2 of all 25 regressions. Obviously i can do them individually by running P1<-lm(formula = df[1:24,1] - RiskFree ~ Mkt.RF + SMB + HML, data = df ) summary(P1)$r.squared 25 times to get all the r.square which is really time consuming (can't imagine if it's 100 or greater). I thought of doing a loop and here is where i got stuck. This is what i did sequence<-seq(1,25) P<-cbind(sequence) for(i in 2:26){ P[i