R错误:“}中的意外'}'我看不到我的代码出错的地方:(

时间:2013-06-14 17:01:40

标签: windows r statistics

我经常按功能运行,它们运行完美。不幸的是,在这里我收到一个错误,我认为这是破坏我的整个代码的根源:S任何建议将不胜感激。附:我对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)

}

1 个答案:

答案 0 :(得分:2)

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

另外,请查看替代方案:Recommendations for Windows text editor for R

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