我有一個結構如下的函式:
function(x, y, z, n = 3){
test = #funky fit with the input data
other = #more metrics
#conditions to evaluate the model
if (condition1 = TRUE){ #condition based on other or test
#rerun function with n = 2
} else if (condition2 = TRUE) {#condition based on other or test
#rerun function with n = 1
} else {
#save the output
}
}
我想知道當滿足條件 1 或 2 分別更改n為 2 或 1時,如何重新運行該函式。我知道while但我不確定如何在這種情況下實施它。
uj5u.com熱心網友回復:
為什么不直接使用遞回?
recurse = function(x, y, z, n = 3){
test = #funky fit with the input data
other = #more metrics
if (condition1){
recurse(x, y, z, n = 2)
} else if (condition2) {
recurse(x, y, z, n = 1)
} else {
# Choose the return value here
other
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/354158.html
標籤:r
