我可以看到這已經差不多完成了,但我是R新手,無法弄清楚。非常多,我有一個迴歸循環(請不要批評數據挖掘),我需要從每個循環中報告一些事情到一個新的列表/數據框/任何最合適的。這裏是我的代碼:循環迴歸提取每個迴歸
#Required packages
require(lattice)
require(plyr)
ACDn <- "ACDn.csv"
x <- as.matrix(read.csv(ACDn, colClasses = "numeric"))
#To find which columns are which, in order to split up the overall dataset.
which(colnames(X)=="H95.H30")
which(colnames(X)=="H99")
#Here i split all the data into their different types, i.e. LHt = Lidar Heights. Please ignore
#those that are unpopulated, as i am waiting on data to run.
Yall <- x[,c(59:79)] #All "True Variables" - BA, MTH, etc.
Y <- Yall[,10] #Specifies which columnn is the Y variable, BA = 10,
#TopHt = 11, SPH = 12, Vol_live = 13, RecovVol = 14
X <- x[,c(1:58,80:95)] #All Lidar metrics and combinations.
LHt <- X[,c(28:41,59:74)]
LCv <- X[,c()]
LKu <- X[,c()]
LSk <- X[,c()]
L?? <- X[,c()]
#Create List file. I
Optmod1 <-
#Loop Creation, need dataset sizes. The ?? are caused by not knowing the exact sizes
#of the relative datasets yet. Somewhere in here i would like the an entry for EACH model to be
#appended to a data.frame (or list, whatever is most appropriate), which would state the variables
# i.e. 'y', 'i', 'j', 'k', 'l', 'm', and the Adj. R-squared value (which i guess can be extracted
# through using 'summary(mod)$adj.r.squared).
For(i in 1:30) {
For(j in 1:??) {
For(k in 1:??) {
For(l in 1:??){
For(m in 1:??){
mod <- lm(Y ~ LHt[i] + LCv[j] + LKu[k] + LSk[l] + L??[m])
}
}
}
}
}
那麼好看多了,以後「國防部」已經跑每一次,我只需要它扔「Y」,「我」,「J」,「K」,「L」 ,'米',並調整.R平方(我想通過使用「摘要(mod)$ adj.r.squared」)到可抽取的表中。
對不起,如果有任何這是r-illiterate,我是新來的,並剛纔給出了規定的代碼,因此我的基本理解是稀疏的。
謝謝你的時間!
P.S.隨時提出任何問題 - 我會努力回答他們!
非常感謝您的回覆。 我的問題是:當我做第二件事你說(最好的做法)我收到一條錯誤消息: > LHT_names = lapply(1:30,paste(「LHt [」,i,「]」,sep =「」)) 錯誤get(as.character(FUN),mode =「function」,envir = envir): 找不到模式'function'的對象'LHt [1]' 我該怎麼做? – Schmakk 2013-03-26 06:23:26
對不起,這是一個錯字...你需要在'paste'之前插入'function(i)'。看看'lapply',並且在它工作時看看那條線的輸出。 – Alex 2013-03-26 06:28:06
Hrmmmm,我到了最後一段代碼,並得到一個錯誤,說'function(x)'後面的「=」是意外的。 – Schmakk 2013-03-26 06:34:36