0

I usually press run on functions and they run perfectly. Unfortunately, here I'm getting an error which I believe is at the root of ruining my entire code :S Any suggestions would be appreciated. P.S. I'm VERY new to R

Code:

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)

}
greedybuddha
  • 7,488
  • 3
  • 36
  • 50
DanRoDuq
  • 260
  • 3
  • 13
  • You have mismatched braces somewhere. If you have an editor that will brace-match for you, that should help you find it. If you don't have such an editor, strongly consider getting one -- it will help you greatly in the long run. – Hong Ooi Jun 14 '13 at 17:05

1 Answers1

2

This is not a question for SO. You need to be looking for a better editor that provides you Syntax Highlighting, paren matching etc. If you are a beginner, I'd recommend RStudio.

Also, look here for alternatives: Recommendations for Windows text editor for R

For where your code is going wrong, please look at @Andreas solution above.

Community
  • 1
  • 1
asb
  • 4,392
  • 1
  • 20
  • 30