问题描述
我在具有所有数值的 data.frame
上运行 cor()
结果是:
I'm running cor()
on a data.frame
with all numeric values and I'm getting this as the result:
price exprice...
price 1 NA
exprice NA 1
...
所以要么是 1
或 NA
表示结果表中的每个值。为什么显示 NA
而不是有效的相关性?
So it's either 1
or NA
for each value in the resulting table. Why are the NA
s showing up instead of valid correlations?
推荐答案
1
是因为一切与自身完全相关,而 NA
s是因为存在 NA
中的变量。
The 1
s are because everything is perfectly correlated with itself, and the NA
s are because there are NA
s in your variables.
您必须指定在缺少值时希望R如何计算相关性,因为
You will have to specify how you want R to compute the correlation when there are missing values, because the default is to only compute a coefficient with complete information.
您可以使用 use
参数更改此行为。 cor
,有关详细信息,请参见?cor
。
You can change this behavior with the use
argument to cor
, see ?cor
for details.
这篇关于cor的相关性仅显示NA或1-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!