mardi 1 mai 2018

R - Change value of a variable based on two conditions

I'm looking for a way to have R:

  1. check for a certain value in a column A

  2. and if it finds it, then look at the corresponding value in a column B in a corresponding row

  3. and change the corresponding value in a column C based on this.

    I.e. something like

data$C[if(data$A==X) AND if(data$B==Y)] = 1

I will try to illustrate it on an example.

Item Response Category
A    10
B    5

"If the Item is A and the Response is below 7, enter 1 into Category"

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire