Assuming I have a dataset:
X Y
1 0 500
2 125 375
3 250 250
4 375 125
5 500 500
6 750 250
....
....
which can be generated by:
df <- data.frame(X = c(0,125,250,375,500,750), Y=c(500,375,250,125,500,250))
I need to assign a category value based on the numerical relationship of X
and Y
. For example:
if X=0, then assign label A
if Y>X and Y/X=3 then assign label B
if X=Y then assign label C
if X>Y and X/Y=3 then assign label D
So essentially, I am assigning labels based on the ratio of X and Y: 0, 0.25, 0.75, 1. So the end result I am hoping for it:
X Y Category
1 0 500 A
2 125 375 B
3 250 250 C
4 375 125 D
5 500 500 C
6 750 250 D
....
....
How should I accomplish this? Thanks