r - 数字变量和 boolean 变量之间的相关性

标签 r statistics boolean numeric correlation

我正在 R 中创建一个情节,使用:

plot(IQ, isAtheist)
abline(lm(isAtheist~IQ))

智商是 numericisAtheist是 boolean 值,具有值 TRUEFALSE .

enter image description here

我试着写:
cor(IQ, isAtheist)

但它给了我一个错误:
Error in cor(IQ, isAtheist) : 'x' must be numeric

如何确定这两个变量之间的相关性?

最佳答案

我真的不知道你想如何解释这种情况下的相关性,但你可以试试 cor(IQ, as.numeric(isAtheist)) .
在这种情况下,TRUE 将为 1,FALSE 将为 0。

关于r - 数字变量和 boolean 变量之间的相关性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12993195/

相关文章:

c - GPIO 引脚控制 SAMC21

function - 如何创建haskell排列

c++ - 标准 C++ 中是否有固定宽度的 bool 类型?

r - 如何在 R 中可视化大型网络?

haskell - 为什么数据构造函数不在此处的范围内

python - Numpy中快速计算大数集标准差的方法

c++ - 用 C++ 快速实现反不完全 Beta 函数

javascript - 更改 selectInput 和 numericInput 框的外观/形状

javascript - 如何在下面的图上显示所有月份(轴刻度/中断)? (右)

r - 每小时时间序列绘图