I am trying to find a way to automatically adjust the model formula that R will use to fit any sort of model. Here is a simple example. In the code below I want to be able to choose if I want to include "a" and "b" into the model or not by providing "include.a/b". If I choose "TRUE" it should be included into the model formula, if not left out.
x=1:10
y=2:11
y[9] = y[9]+1
a = rep(3, times = 10)
a[7] = 7
b = c(3:10, 10, 10)
include.a = FALSE
include.b = TRUE
# to get the model y ~ x + b
model = lm(y ~ x
if(include.b == TRUE){+ b)}
)
I've been searching this website everywhere but cannot find any hints.