0

我通常按​​功能运行,它们运行良好。不幸的是,在这里我遇到了一个错误,我认为这是破坏我的整个代码的根源: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)

}
4

1 回答 1

2

这不是 SO 的问题。你需要寻找一个更好的编辑器来为你提供语法高亮、括号匹配等。如果你是初学者,我推荐 RStudio。

此外,请在此处查找替代方案:R 的 Windows 文本编辑器的建议

对于您的代码出错的地方,请查看上面的@Andreas 解决方案。

于 2013-06-14T17:09:00.663 回答