r - Reading Multiple CSV files and perform a logistic regression for all those files separately
问题描述
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
解决方案
您可以使用以下内容读取所有 csv 文件:
temp = list.files(pattern="*.csv")
myfiles = lapply(temp, read.csv)
接下来,您可以使用以下命令一次运行回归模型:
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)
推荐阅读
- javascript - 使用相同数据更新 UI 多个部分的 jquery 策略
- python - 使用破折号创建仪表板时出现回调错误
- r - 用于在列上运行函数的 for 循环
- python - 在 Astropy 中转换为黄道坐标
- javascript - React spring 动画下拉列表,其内容来自状态但折叠时不保持状态
- python - 获取 elif 无效语法,尝试寻找解决方案,但到目前为止没有任何效果
- python - 如何为单行模式编写迭代代码?
- python - 如何抓取网站内的特定链接?
- r - R中没有替换的多个随机样本
- r - r- 绑定数据帧列表的行,同时将空数据帧保留为 NA 行