Having reached the limit of the IF ELSE Statement in R i am hoping there will be another way to achieve the same outcome -
I have a max of a count and the count. If Count == Max Count THAN 1 ELSE IF Count = Max Count - 1 THAN 2 ELSE IF Count == Max Count - 2 THAN 3 ETC.... through to 70.
I have written this code. and R fire out this error Error: contextstack overflow at line - Upon Googling this it looks as though i have reached the threshold of possible nested statements hence me looking for a better way to achieve same result.
DF$`Score` <- ifelse(DF$Max_30_Day_Count == DF$`30_Day_Count`,
1,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-1),
2,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-2),
3,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-3),
4,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-4),
5,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-5),
6,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-6),
7,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-7),
8,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-8),
9,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-9),
10,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-10),
11,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-11),
12,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-12),
13,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-13),
14,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-14),
15,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-15),
16,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-16),
17,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-17),
18,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-18),
19,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-19),
20,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-20),
21,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-21),
22,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-22),
23,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-23),
24,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-24),
25,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-25),
26,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-26),
27,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-27),
28,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-28),
29,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-29),
30,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-30),
31,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-31),
32,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-32),
33,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-33),
34,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-34),
35,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-35),
36,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-36),
37,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-37),
38,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-38),
39,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-39),
40,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-40),
41,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-41),
42,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-42),
43,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-43),
44,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-44),
45,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-45),
46,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-46),
47,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-47),
48,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-48),
49,
ifelse(DF$Max_30_Day_Count == (DF$`30_Day_Count`-49),
50,
0))))))))))))))))))))))))))))))))))))))))))))))))))
If count is 1 and Max count is 5 the result should be 5 if Count is 5 and max count is 5 the result should be 1 and all numbers in between up to 100
Aucun commentaire:
Enregistrer un commentaire