26個の.csvファイルを含むフォルダがあります。各ファイルには、ヘッダーがDO2
とTime_min
の2つの列があり、すべてに少なくとも300以上の行があります。私が欲しいディレクトリ内の複数のファイルをループするリニアモデル
がそれぞれの線形モデルを作り、x=Time_min
とy=DO2
で散布を行い、26モデルのそれぞれについてcoefficient
とR^2
を取り、テーブルにそれを置きます。
これはコードが書かれている限り私が書いたものです。私はそれをコピーして貼り付けることができますが、よりスマートな方法が必要であることも知っています。
setwd("~/Documents/Masters/Data/R/35789/35789_Ucrit")
#The file where I want all the coefficients and R^2 to go
UE_Slope <- read.csv("~/Documents/Masters/Data/R/35789/35789_UE_Slope.csv")
temp = list.files(pattern="*.csv")
for (i in 1:length(temp))(assign(temp[i], read.csv(temp[i])))
#Seal# are the names for the files directory, 1-26
plot(DO2 ~ Time_min, data = Seal1)
model1 <- lm(DO2 ~ Time_min, data = Seal1.csv)
UE_Slope <- rbind(UE_Slope, data.frame("Slope"=coef(model1)[[2]], "R.2"=summary(model1)$r.squared))
割り当てを使用する代わりに、リスト内のオブジェクトに追加することをお勧めします。lst [ - temp [i]] < - read.csv(temp [i]) ' –