Simple way to fit large number of single factor logistic regression models in R - automatically I have a dataset with one binary target variable called “target” and many many factors “F1”, F2”… “F200”. I’m trying to come up with code to fit 200 single factor logistic regression models and return the model summaries. Here is what I have so far
single <- function(df, factor){
    s <- summary(glm(as.formula(paste('target ~ ', factor, sep='')), family=binomial, data=df));
return(s);
}
single(data, c("F1", "F2", "F2"));

but this gives me only a summary of the first model. Am I missing something obvious here?
 A: Here's a solution using lapply. It will return a list of model summary objects.
lapply(c("F1", "F2", "F3"),
       function(x) summary(glm(df[["target"]] ~ df[[x]], family=binomial)))

Your codes does not work because you run paste('target ~ ', c("F1", "F2", "F2"), sep='') which results in "target ~ F1" "target ~ F2" "target ~ F2". Converted to a formula, it returns target ~ F1.
Update
A solution which returns a matrix of regression results.
An example data frame:
set.seed(42)
df <- data.frame(target = sample(0:1, 10, TRUE),
                 F1 = rnorm(10), F2 = rnorm(10), F3 = rnorm(10))


predictors <- c("F1", "F2", "F3")    
fits <- sapply(predictors,
               function(x) {
                 tmp <- try(coef(summary(glm(as.formula(paste("target", x, sep = "~")),
                                             family=binomial, data = df)))[2, ], TRUE)
                 if (class(tmp) == "try-error") NULL else tmp})

The result (fits):
                   F1         F2        F3
Estimate   -0.1864527 -1.2242511 0.6751601
Std. Error  0.8259677  1.0915999 0.8770035
z value    -0.2257384 -1.1215200 0.7698488
Pr(>|z|)    0.8214049  0.2620666 0.4413896

