问题
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