base R answer
# Replace '...' with the path to the directory with your files.
files <- list.files(..., pattern="\\.csv$", full.names=TRUE)
files <- setNames(files, basename(files))
results <- lapply(files, function(x) {
df <- read.csv(x, stringsAsFactors=FALSE)
df$fan <- as.numeric(df$fan > 0)
result <- glm(
Event ~ T-ctrl + T_out + RH_out + T_stp_cool + T_stp_heat + Humi,
data=df, family=binomial(link="logit")
)
result <- summary(result)$coefficients
return(result)
})
data.table will speed things up a bit if the files are big and/or you have a lot of files.
library("data.table")
# Replace '...' with the path to the directory with your files.
files <- list.files(..., pattern="\\.csv$", full.names=TRUE)
files <- setNames(files, basename(files))
results <- lapply(files, function(x) {
DT <- fread(x, sep=",")
set(DT, j="fan", value=as.numeric(DT[, fan] > 0))
result <- glm(
Event ~ T-ctrl + T_out + RH_out + T_stp_cool + T_stp_heat + Humi,
data=DT, family=binomial(link="logit")
)
result <- summary(result)$coefficients
return(result)
})