0

Sorry, but I totally suck with for/while loops.

How can I correctly write the loop function until needed value is reached? Basically I have this kind of function:

kendall(QK(1, B_6x6, 0.1), correct = TRUE)$value
kendall(QK(2, B_6x6, 0.1), correct = TRUE)$value
kendall(QK(3, B_6x6, 0.1), correct = TRUE)$value
.....etc.

but I need it to run untill this value will be equal 1.

like..

for (i in 1:99) {
kendall(QK(i, B_6x6, 0.1), correct = TRUE)$value
}

But how to correctly express this condition, so I could know which i this condition is reached? Thank you very much for any input!

Ally
  • 23
  • 3
  • Assign the value to `v` and test `if(abs(v - 1) < .Machine$double.eps^0.5) break` – Rui Barradas May 17 '22 at 14:04
  • Instead of looping with a fixed step, an approximation (e.g. the venerable secant method) might be faster. Package {cmna} provides this and other algos: `cmna::secant(f = function(x){ kendall(QK(x, B_6x6, 0.1), correct = TRUE)$value - 1 }, x = meaningful_start_value, tol = .01, ## desired tolerance m = 20 ## max iterations )` –  May 17 '22 at 14:11

0 Answers0