mardi 16 février 2016

Swapping out variables with multiple conditionals in R

this is my reproducible example:

SMTscenes.ACC SMTscenes.RESP TrialType 
0             4              Old
0             3              Old
0             r              New
0             2              New
0             1              New
0             r              Old
0             3              Old

I'm trying to make an R script that has the following conditions:

If 'SMTscenes.RESP' => 3 or = 'r', AND 'TrialType' = 'Old' then make 'SMTscenes.ACC' = 1

Else, keep it as is.

I tried looking at other questions and how they were answered, but I couldn't implement the functions to mine, particularly because of 'r' not simply being a '5'.

It should look like:

SMTscenes.ACC SMTscenes.RESP TrialType 
    1             4              Old
    1             3              Old
    0             r              New
    0             2              New
    0             1              New
    1             r              Old
    1             3              Old

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire