0

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.

Tom
  • 2,173
  • 1
  • 17
  • 44

0 Answers0