mercredi 5 août 2020

Trying to update a dataframe with an if/else statement [duplicate]

I have a data frame df with 100 rows. I am trying to make it so that if certain column values in each row equal certain things, I change another column value.

So in this example, for each row in the data frame, if the "subject" column value is = s002 and Deviant = 101 and Correct = 222, I want the column of "Correct Final" to be changed to 1

for (i in 100) {
df$CorrectFinal<- if (df$subject == "s002" && df$Deviant == 101 &&
 df$Correct == 222) (df$CorrectFinal == 1) else (df$CorrectFinal == 0)}

Aucun commentaire:

Enregistrer un commentaire