After running m1 <- lm(f1, data=DT) I want to save the included observations (similar to "obs <- complete.cases (m1), but something that works) so that I can perform a second regression with those the same observations: m2 <- lm(f2, data=DT[obs]) .
Alternatively, I would like to get observations that are complete for a given set of variables, as defined by the formula object. Consider this R-like pseudocode:
f1 <- as.formula("y ~ x1 + x2 + x3") f2 <- as.formula("y ~ x1 + x2") obs <- complete.cases(DT[,list(all.vars(f1)]) m2 <- lm(f2, data=DT[obs])
How can I do it? In the first case, lm already doing the work implicitly; how can i extract it? In the second, all.vars returns a character vector; how to create a list without quotes that understands DT (data.table)?
source share