cor的相关性仅显示NA或1-为什么? [英] cor shows only NA or 1 for correlations - Why?

查看:180
本文介绍了cor的相关性仅显示NA或1-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有所有数值的 data.frame 上运行 cor()结果是:

I'm running cor() on a data.framewith 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 NAs showing up instead of valid correlations?

推荐答案

1 是因为一切与自身完全相关,而 NA s是因为存在 NA 中的变量。

The 1s are because everything is perfectly correlated with itself, and the NAs are because there are NAs 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-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆