我通常按功能运行,它们运行良好。不幸的是,在这里我遇到了一个错误,我认为这是破坏我的整个代码的根源:S 任何建议都将不胜感激。PS我对R很陌生
代码:
CoefficientSorter=function(List1){
for (p in 1: length(List1)){
length(List1)
XAxis=seq(from = 1, to =length(List1[[p]])/2 , by = 1)
ProperYvalues=rev(List1[[p]][,2])
RegressionLine=lm(ProperYvalues~XAxis)
Title= paste(ThreePeriodCounter, a[p])
plot(XAxis,ProperYvalues, main=Title)
abline(RegressionLine$coefficients)
Coefficients=RegressionLine$coefficients
names(Coefficients)=NULL
if (Coefficients[2]<0){
TemporaryVect=c(p, Coefficients[2])
if (!exists("NegSlopeVect")){ NegSlopeVect= TemporaryVect}
else{NegSlopeVect=rbind(NegSlopeVect, TemporaryVect, deparse.level=0)}
rm(TemporaryVect)
}
else {
if (Coefficients[2]>0){
TemporaryVect=c(p, Coefficients[2])
if (!exists("PosSlopeVect")){PosSlopeVect= TemporaryVect}
else{
PosSlopeVect=rbind(PosSlopeVect, TemporaryVect, deparse.level=0)
}
rm(TemporaryVect)
}
}
else {
counter=counter+1
}
rm(RegressionLine)
rm(Coefficients)
rm(ProperYvalues)
}
TrialList2=list("PosSlopeVectR"=PosSlopeVect, "NegSlopeVect"=NegSlopeVect)
return(TrialList2)
}