首页 > 解决方案 > R中data.farme中所有变量的相关性

问题描述

我知道输入一个 data.framecor会自动给出一个相关矩阵(例如cor(mtcars))。

但我想知道为什么当我输入自己的 data.frame ( dat_w) 时cor会出现以下错误?

我有NA并且Inf已经使用了use = 'pairwise.complete.obs'.

dat_w <- read.csv('https://raw.githubusercontent.com/izeh/n/master/w1.csv', stringsAsFactors = F)


cor(dat_w, use = 'pairwise.complete.obs')

# >Error : 'x' must be numeric

标签: rdataframelapplycorrelation

解决方案


因为您的第二列 ( gender) 不是数字。尝试 :

cor(dat_w[-2], use = 'pairwise.complete.obs')

推荐阅读