I'm trying to perform interaction test on a dataset with 23 variables. Following is a loop for interaction terms test among all variables, but the code does not retain variable tested before. How to make the correction allowing summary to display interaction among all variable such as xyz rather than xy and yx separately?
vars=colnames(happiness_logper1)[-1]
varHap <- rep(0,100)
for (i in vars) {
for (j in vars) {
if (i != j) {
varHap= paste(i,j,sep='*')}
lm.fit <- lm(paste("Happiness.in.life ~", varHap), data=happiness_logper1)
print(summary(lm.fit))
}
}