我写了一个非常简单的虚拟函数来表示:
a<-c(1:3,"s",5:10)
testFunction<-function(x,a){
for (i in 1:10){
print(log(x)/log(a[i]))
}
}
testFunction(2,a)
我想要的输出是:
[1] Inf
[1] 1
[1] 0.6309298
<This is where the loop is skipped because of the error, but does not cause the loop to stop>
[1] 0.4306766
[1] 0.3868528
[1] 0.3562072
[1] 0.3333333
[1] 0.3154649
[1] 0.30103
请建议一个代码来实现上述目标,其中循环不会中断并继续执行其余的迭代
答案 0 :(得分:0)
所以...... Log(1)= 0 ..你要除以0.