且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用循环从线性回归中提取系数输出

更新时间:2023-12-02 13:51:40

@jogo给出了一种更改for循环方法并使用sapply的想法,并将对象beta更改为list().结果就是这样:

@jogo give an idea to change the for-loop method and use sapply, and change the object beta to list(). This was the result:

beta <- sapply(1:n, function(i) coef(lm(Premium ~ Liquidity +Leverage+ hubris_dataset[,i], data=dt_deals2)))

它奏效了