Say I have a training set in a data frame train
with columns ColA
, ColB
, ColC
, etc. One of these columns designates a binary class, say column Class
, with "yes" or "no" values.
I'm trying out some binary classifiers, e.g.:
library(klaR)
mynb <- NaiveBayes(Class ~ ColA + ColB + ColC, train)
I would like to run the above code in a loop, automatically generating all possible combinations of columns in the formula, i.e.:
mynb <- append(mynb, NaiveBayes(Class ~ ColA, train)
mynb <- append(mynb, NaiveBayes(Class ~ ColA + ColB, train)
mynb <- append(mynb, NaiveBayes(Class ~ ColA + ColB + ColC, train)
...
mynb <- append(mynb, NaiveBayes(Class ~ ColB + ColC + ColD, train)
...
How can I automatically generate formulas for each possible linear model involving columns of a data frame?