mercredi 2 décembre 2020

ifelse() returns logical(0) when trying to change values

right now I am trying to omit specific trials from my data frame. If peoples response times to a certain scenario they saw is too long or too short, I want to exclude these trials from my analysis. I already identified the observations, and now I want to replace them with NAs. For this, I wanted to use an ifelse()- Statement. If their response time log_TIME is above or below a certain threshold (above 5.3 or below 2.01), then I want to replace their answers to those scenarios in the variable answer coded with 0 and 1, to be NA.
My data looks something like this:

logTIME001    answer001

2.944439      1
3.912023      1
3.583519      0
1.098612      1
3.850148      0
5.700444      1

This is the code I tried:

ifelse(df$logTIME001 > 5.310, df$answer001 == "NA")
ifelse(df$logTIME001 < 2.01, df$answer001 == "NA")

But if I do this, it returns logical(0) and all of the values in answer001 turn to NAs. How can I fix this? Is this even the correct code or do I have to use a different one? Thank you for your help! :)

Aucun commentaire:

Enregistrer un commentaire