2016-05-30 3 views
0

私は表現のための非常にシンプルなダミー関数書かれています:エラー処理 - 簡単な例R

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

したがって.. Log(1)= 0 .. 0で割っています。

+0

こんにちはalphaadidas、あなたが正しいです、与えられた数字は表現的です。文字通り取らないでください。 –