I have column A with values. I want to divide the values from column A by 2 or 3 IF they meet the following conditions:
Condition 1: If Column B and Column C = 250, then divide Column A by 2; Condition 2: If column C and Column D = 250, then divide Column A by 2; Condition 3: If Column B and Column C and Column D = 250, then divide Column A by 3
Condition 4: If Column B and Column C = 500, then divide Column A by 2; Condition 2: If column C and Column D = 500, then divide Column A by 2; Condition 3: If Column B and Column C and Column D = 500, then divide Column A by 3
and so on....
In other words, if two columns (from B, C and D) have the same 2 values, divide by 2 or if three columns have the same 3 values, divide by 3.
As an example the data is:
A B C D
0.666667 250 500 250
0.666667 500 500 1000
0.666667 250 1000 1000
0.666667 500 500 1000
0.666667 250 500 500
0.666667 250 500 500
As for the counts here is what I would get after the first part of the condition for example in row 1 there are 2 - 250 and 1 - 500 hence 2,1,2 corresponding to columns B1, C1, D1:
A B C D B1 C1 D1
0.666667 250 500 250 2 1 2
0.666667 500 500 1000 2 2 1
0.666667 250 1000 1000 1 2 2
0.666667 500 500 1000 2 2 1
0.666667 250 500 500 1 2 2
0.666667 250 500 500 1 2 2
I now need to divide column A by B1, A by C1, A by D1 to give me three new columns AR, BR, CR
A B C D BR CR DR
0.666667 250 500 250 0.333 0.667 0.333
0.666667 500 500 1000 0.333 0.333 0.667
0.666667 250 1000 1000 0.667 0.333 0.333
0.666667 500 500 1000 0.333 0.333 0.667
0.666667 250 500 500 0.667 0.333 0.333
0.666667 250 500 500 0.667 0.333 0.333
0.666667 500 500 500 0.222 0.222 0.222
I am still trying to work out the code.
data %>% mutate(A1 == ifelse(B == 250 & C == 250, A/2, ifelse(B == 250 & D == 250, A/2, ifelse(B == 250 & C == 250 & D == 250, A/3))
data %>% mutate(A1 == ifelse(B == 500 & C == 500 , A/2, ifelse(B == 500 & D == 500 , A/2, ifelse(B == 500 & C == 500 & D == 500, A/3))
data %>% mutate(A1 == ifelse(B == 1000 & C == 1000 , A/2, ifelse(B == 1000 & D == 1000 , A/2, ifelse(B == 1000 & C == 1000 & D == 1000, A/3))
I get a + asking for more code.
Any help would be most appreciated. Thank you!