In order to increase readability, I want to filter my data frame before I pipe it into a regression model. For some reason - however - this does not seem to be possible.
I can write something like:
model<-lm(mpg~.,data=mtcars)%>%¨
stepAIC(trace = FALSE)
....And that works perfectly, even with the pipe at the end. But then I try to replace the data argument with a placeholder:
model<-df%>%lm(mpg~.,data=.)%>%
stepAIC(trace = FALSE)
....And I get an error claiming that:
Error in as.data.frame.default(data) :
cannot coerce class ‘"lm"’ to a data.frame
This issue only seems to occur when I'm using the stepAIC-function. Unfortunatly that's a requirement for my current project.
Can I make this work and in that case how?