jeudi 17 août 2017

Cannot use nested if in for statement in R

for ( i in 1:2493658) { If (newcol2[i,3]== newcol2[i+1,3]) { newcol2[-c(i+1),]}}

I want to check if [1,3] and [2,3] are same. If yes then delete the second row. This loop goes on until the end which is 2493658.

But it throws this error: unexpected '{' in "for ( i in 1:2493658) { If (newcol2[i,3]== newcol2[i+1,3]) {"

Any other functions like sapply, rbind would help?

Aucun commentaire:

Enregistrer un commentaire