I am able to carry out something like the following:
foo=data.frame(y=rnorm(100),x1=rnorm(100),x2=rnorm(100),x3=rnorm(100))
full=lm(foo$y ~ foo$x1 + foo$x2 + foo$x3)
nil=lm(foo$y ~ 1)
fwd=step(nil,scope=list(lower=formula(nil),upper=formula(full)),direction='forward')
But I'm working with data.table like so:
library(data.table)
foo=data.table(y=rnorm(100),x1=rnorm(100),x2=rnorm(100),x3=rnorm(100))
full=foo[,lm(y ~ x1 + x2 + x3)]
nil=foo[,lm(y ~ 1)]
fwd=foo[,step(nil,scope=list(lower=formula(nil),upper=formula(full)),direction='forward')]
And I get the error:
Error in eval(expr, envir, enclos) : object 'x1' not found
But x1
is defined inside the J expression above for data.table - is there a way around this without having to convert my table to a data.frame?