# [R] create data frame with coefficients from many regressions

Mon Jul 22 23:04:23 CEST 2013

```Hello,

Using Arun's data example, you can also do the following.

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))

lm.list <- lapply(seq_len(ncol(dat1)), function(i) lm(dat1[,i] ~ dat2[,i]))

do.call(cbind, lapply(lm.list, coef))   # object of class "matrix"

Hope this helps,

Em 22-07-2013 20:11, iza.ch1 escreveu:
>
>> Hi !
>>
>> I want to ask if somebody knows the way to create data frame with coefficients from many regressions
>> I regress the first column from ret against the first columns from median, then the second with the second and so on.
>> This is the code used for regression
>>
>> i<-1:6
>> lapply(seq_len(ncol(ret)),function(i) {lm(ret[,i]~median[,i])}
>>
>> I get 6 results for each regression
>>
>> []
>>
>> Call:
>> lm(formula = ret[, i] ~ median[, i])
>>
>> Coefficients:
>> (Intercept)  median[, i]
>>            0            1
>>
>>
>> []
>>
>> Call:
>> lm(formula = ret[, i] ~ median[, i])
>>
>> Coefficients:
>> (Intercept)  median[, i]
>> -1.411e-17    1.000e+00
>>
>> now I would like to create a data frame with intercepts which looks like it
>>
>>                          []          []
>> Intercept
>> median
>>
>> I tried to use ddply command but it does not work. I will be very grateful for the hint :)
>>