0

I am trying to perform a logistic regression analysis on multiple CSV files. All the files have the same column's name ( DateTime, HvacMode, Event, Schedule,...). How can I load all the CSV files in the folder and perform a logistic using one Rstudio code for all the CSV files and I will be able to refer to each analysis's result in the future. My goal is to find a pattern in different CSV samples.

for a single file I use

glm(Event ~ T_ctrl + T_out+RH_out+ T_stp_cool+T_stp_heat+Humi, data=logistic, 
                        family=binomial(link="logit"))

and I need to do this for all the csv files in WD.

Thank you

Phil
  • 7,287
  • 3
  • 36
  • 66
  • This is the third time you're essentially asking the same question (how to load multiple csv files from a directory). https://www.gerkelab.com/blog/2018/09/import-directory-csv-purrr-readr/ https://stackoverflow.com/questions/11433432/how-to-import-multiple-csv-files-at-once – Phil Sep 06 '20 at 20:48

1 Answers1

2

You can use the following to read in all of your csv files:

temp = list.files(pattern="*.csv")
myfiles = lapply(temp, read.csv)

Next, you can run your regression models at once using:

regression = function(df) {
  glm(Event ~ T_ctrl + T_out + RH_out + T_stp_cool + T_stp_heat+Humi, data = df, 
                        family = binomial(link = "logit"))
}

models = map(myfiles, regression)
Emily Halford
  • 169
  • 1
  • 7