There is a problem with the Ielse evaluation.
The following conditions evaluate on the basis of 3 positions:
mk < - Function (a, b, c, d, e_1, e_2, f, k) # condition 1 ifelse (! Is.na (e_1) &! (K% in% 1), Mk & Lt; - D - E_1 * C, # condition2Ifel (! ISANA (E2) and! (% Of% in%), MK & LT; - EOD - D * C, # Condition 3 Ifelse (a - b) & lt; = 11 , Mk & lt; -c * a - b * f, mk & lt; -c * f)))
If I parse a single element correctly evaluates , But if I give lines of input value, then the function only uses computation in the previous state, even if the previous conditions are met. There is some NA in the column for value E_1, e_2 and, I suspect that there is a problem. Which I do not get, so NA's strength should be evaluated as the whole vector 3 position, even if their calculation is never really, because the conditions should be excluded from their use. If I change the calculation with the characters, that is, instead of the formulas, use "1/2/3 position", the conditions are properly evaluated.
How can I avoid this problem?
Excluding the NAS The cause of the problem was not at all, but rather a round operation after the initial assessment . The round function was not in my first question because I did not suspect this problem, but it is actually the cause of the problem.
My problem is represented in a more simply way:
mktest < - Function (a, b, e_1, e_2, k) {# condition 1 ifelse (! Is.na (e_1) & amp; (% in% 1), Mk & Lt; - 1 - e_1, # condition 2 Ifelse (! Is.na (e_2) &! (% In%%), Mk & lt; - 2 - e_2, # condition 3 ifelse ((a - b) & lt; = 1, mk & lt; - a * B, MK & LT; - A * 2)) Round (Mk, 0)} # In my data frame test, some testadata with all possible combinations of values & lt; - Name (test) [1] <- data (frame) (expanded grid (2: 3, 1, c (1, n), c (1, na), c (0,1, na) A "name (test) [2] & lt; -" b "name (test) [3] <-" e_1 "name (test) [4] <-" e_2 "name (test) [5 ] <- "k" # imagine conditions $ condo 1 & lt;!! Is.na (test $ EDI) & amp;! (Test in% K %%) test $ cond2 & lt; -! $ (Test $ a - test $ b) & lt; = 1) # results test results $ & mtest ($ test $ k_2%) ; - mktest (test $ a, test $ b, Test $ E_1, test $ e_2, test $ k)
If I evaluate it without a round (Mk, 0) without function, then these conditions are properly If the goal is scored, then only the final position is used. The reason for this behavior is still away from me, because the spherical operating conditions are done after evaluation, but at least the problem is solved in the hand Has been done.
Comments
Post a Comment