'Using loops to do Chi-Square Test in R

I am new to R. I found the following code for doing univariate logistic regression for a set of variables. What i would like to do is run chi square test for a list of variables against the dependent variable, similar to the logistic regression code below. I found couple of them which involve creating all possible combinations of the variables, but I can't get it to work. Ideally, I want the one of the variables (X) to be the same.

Chi Square Analysis using for loop in R

lapply(c("age","sex","race","service","cancer",
         "renal","inf","cpr","sys","heart","prevad",
         "type","frac","po2","ph","pco2","bic","cre","loc"),

       function(var) {

         formula    <- as.formula(paste("status ~", var))
         res.logist <- glm(formula, data = icu, family = binomial)

         summary(res.logist)
       })


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source