Hi, set.seed(28) dat1<- as.data.frame(matrix(sample(1:20,100,replace=TRUE),ncol=10)) set.seed(49) dat2<- as.data.frame(matrix(sample(40:80,100,replace=TRUE),ncol=10)) lapply(seq_len(ncol(dat1)),function(i) {lm(dat2[,i]~dat1[,i])}) A.K.
----- Original Message ----- From: iza.ch1 <iza....@op.pl> To: r-help@r-project.org Cc: Sent: Saturday, July 20, 2013 7:55 PM Subject: [R] Linear regression repeat for each column Hi everyone I need to calculate abnormal returns for different events applying event study methodology. I must create a market model in order to perform the analysis. I apply regression analysis to get OLS estimators. I have a problem to create a linear regression which I could repeat for each column in two different data frames (one with explainatory and one with explaning variables). It means that I want to regress column 1 from first data frame with column 1 from second data frame,, clumn two with column two etc. I tried to use the following code:#x is matrix containing stock returns y is matrix containing market index i<-1:length(x) t[i] <- lapply(t[i], lm(x[,1]~y[,i])) but it is not working. Could anybody help me? Thanks a lot Iza ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.