jeudi 5 mars 2020

ifelse using some conditions in R

my data set is similar to this and I want to use ifelse or other functions in R. I can do it easily in Excel, but not sure how to do it it in R.

df<-read.table(text=" Items      Goods
        
Mug1    Cup1
Mug1    Mug2
Mug1    NA
Mug2    Mug1
Mug2    Cup2
Cup1    Mug1
Cup2    Mug2
Mug2    Cup1
Cup1    Mug2", header=TRUE)

Conditions are:

Mug1=Cup1
Mug2=Cup2
Cup1=Mug1
Cup2=Mug2

If I see  the above condition, They are  considered as correct. otherwise they are incorrect. I have searched, but I could not find any solution, but it is likely I have missed some websites. Any help 

I will get this table then

Items       Goods   Out
Mug1    Cup1    Correct
Mug1    Mug2    Incorrect
Mug1    NA      NA
Mug2    Mug1    Incorrect
Mug2    Cup2    Correct
Cup1    Mug1    Correct
Cup2    Mug2    Correct
Mug2    Cup1    Incorrect
Cup1    Mug2    Incorrect

Aucun commentaire:

Enregistrer un commentaire