dimanche 21 juin 2020

Removing middle row using a for loop

There are 42 rows in my dataset(EP) and i want to remove the middle entries for participants. The follow code works but its giving an error:

Error in if (EP$Name[row] == EP$Name[row + 1]) { : missing value where TRUE/FALSE needed

for (row in 2:length(EP$Name)){

    if(EP$Name[row] == EP$Name[row+1]) 
    {
        if(EP$Name[row]==EP$Name[row-1])
        {
         EP <- EP[-row,]
          print(row)
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire