たとえば、実行した場合:
cor(rep(1,7), rep(1,7))
Error in cor(rep(1, 7), rep(1, 7)) :
(converted from warning) the standard deviation is zero
1: cor(rep(1, 7), rep(1, 7))
2: .signalSimpleWarning("the standard deviation is zero", quote(cor(rep(1, 7), rep(1, 7))))
3: withRestarts({
.Internal(.signalCondition(simpleWarning(msg, call), msg, call))
.Internal(.dfltWarn(msg, call))
}, muffleWarning = function() NULL)
4: withOneRestart(expr, restarts[[1]])
5: doWithOneRestart(return(expr), restart)
これは、同じ名前の列を持つ 2 つのデータ フレームの各列の相関関係を計算するためsapply
にを実行しようとすると問題になります。names(some.data.frame)
約 80 の列があり、列の 1 つにゼロ ベクトルがあり、このクラッシュが呼び出されます。これを回避して代わりに出力する方法はありますNA
か?