Linear regression loop with data.table; “Error in data.table column or argument (nr) is NULL”

孤街浪徒 提交于 2020-01-06 05:27:14

问题


As my dataset is cumbersomely large, I would like to automate some procedures. I found this link, which proposes a linear regression loop, which for the dataset mtcars is as follows:

data.table(mtcars)[, .(MyFits = lapply(.SD, function(x) if(is.numeric(x)) summary(lm(mpg ~ x)))), .SDcols = -1] 

I have tried to apply this onto my own dataset with limited succes. I do get the output but there is a problem. The result for some of the Fits is NULL, so when I try to do the suggested operation Fits[, lapply(MyFits, coef)] I get:

Error in data.table column or argument 3 is NULL

Can I somehow make Fits[, lapply(MyFits, coef)]skip the MyFits which are NULL?

EDIT: Question to which the comments refers has been removed for clarity.

来源:https://stackoverflow.com/questions/51989631/linear-regression-loop-with-data-table-error-in-data-table-column-or-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!