I have a data frame with 2 variables:
Correct FACE.RESP
1 1 1
2 2 1
3 1 2
4 2 2
5 2 2
6 2 1
I would like to recode/replace the values in the 'FACE.RESP' column under a condition that if the value in 'FACE.RESP' matches the value in 'Correct', the value in 'FACE.RESP' should be rewritten to 1. If the value in 'FACE.RESP' doesn't match the value in 'Correct', the value in 'FACE.RESP' should be recoded to 0.
I tried the following code using mutate and case_when:
mutate(FACE.RESP = case_when(FACE.RESP == Correct ~ '1', FACE.RESP <= Correct ~ '0', FACE.RESP >= Correct ~ '1'))
but the results is this:
Correct FACE.RESP
5 2 2
6 2 1
7 1 NA
8 2 NA
9 2 NA
10 1 NA
Could anyone suggest how to achieve the required outcome and explain what is wrong with the above line of code?