lucyh
lucyh

Reputation: 179

R showed an error message when create a variable in a loop

I wrote my program in Tinn-R. When I ran it in R by using source(), an error message showed. The following example only includes partial loop.

          for (nn in 1:length(nSim))  ##whether the right loop???
              {
              r.all <- c()
              p.final <- array(0, c(15,5))  #1-5 a, b1, b2, b3, b4; 6 group id
              r.reference <- cbind(GRM_sim(t(p.sample[,1]), t(p.sample[,2:5]),sample.all[iS],0,rep(1,sample.all[iS]))

            DIF_ID <-c()
            DIF_index <- rep(0,15)
            for (iC in 1:length(CDIF))
            {
              if (CDIF[iC]==1)
              {
                DIF_ID <- sample(1:15,DIF.all[iDIF.all])   ##consistent DIF 
              }
               for (id in 1:length(DIF_ID))
               {
                  DIF_index[DIF_ID[id]] <-1
               }
              ...

Error in source("120413consistentMH.R") : 120413consistentMH.R:107:17: unexpected symbol 106:
107: DIF_ID

Thanks for your time.

Upvotes: 0

Views: 357

Answers (1)

IRTFM
IRTFM

Reputation: 263421

The error is typical for a missing paren. Get yourself an editor that matches parens or learn to make more liberal use of spaces and carriage returns. The fifth line that scrolls off the end of this webpage is missing a closing paren:

r.reference <- cbind(GRM_sim( t( p.sample[,1]  ), 
                              t( p.sample[,2:5]), 
                               sample.all[iS],0, 
                              rep(1, sample.all[iS])
                               )
                      ^
            missing paren here

Upvotes: 3

Related Questions