dimanche 6 décembre 2015

debug the if statement

I am trying to understand the for and if-statement in r, so I run a code where I am saying that if the sum of rows are bigger than 3 then return 1 else zero: Here is the code

     set.seed(2)
     x 
     x = rnorm(20)
     y = 2*x
     a = cbind(x,y
     hold = c()

Now comes the if-statement

     for (i in nrow(a)) {
     if ([i,1]+ [i,2] > 3) hold[i,] == 1
     else ([i,1]+ [i,2]) <- hold[i,] == 0
    }

I know that maybe combining for and if may not be ideal, but I just want to understand what is going wrong. Please keep the explanation at a dummy level:) Thanks

Aucun commentaire:

Enregistrer un commentaire